Date: Mon, 21 Jan 2019 04:21:43 +0100
Subject: [PATCH 20/88] build: enable eslint checks for ci builds (#67)
---
.eslintignore | 8 +++
.eslintrc.json | 68 +++++++++++++++++++
README.md | 2 +-
azure-pipelines.yml | 4 ++
package.json | 4 ++
packages/eslint-plugin-tslint/README.md | 2 +-
packages/eslint-plugin/README.md | 2 +-
packages/parser/README.md | 2 +-
packages/typescript-estree/README.md | 2 +-
.../tests/ast-alignment/utils.ts | 2 +-
yarn.lock | 10 +++
11 files changed, 100 insertions(+), 6 deletions(-)
create mode 100644 .eslintignore
create mode 100644 .eslintrc.json
diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 000000000000..58fa04212589
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,8 @@
+node_modules
+dist
+jest.config.js
+fixtures
+coverage
+
+packages/typescript-estree/src/estree
+packages/eslint-plugin-tslint/tests
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 000000000000..6c87aaec59ad
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,68 @@
+{
+ "root": true,
+ "plugins": ["eslint-plugin", "@typescript-eslint", "jest"],
+ "env": {
+ "es6": true,
+ "node": true
+ },
+ "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
+ "rules": {
+ "no-mixed-operators": "error",
+ "no-console": "off",
+ "no-undef": "off",
+ "@typescript-eslint/indent": "off",
+ "@typescript-eslint/no-explicit-any": "off",
+ "@typescript-eslint/no-non-null-assertion": "off",
+ "@typescript-eslint/explicit-function-return-type": "off",
+ "@typescript-eslint/explicit-member-accessibility": "off",
+ "@typescript-eslint/no-var-requires": "off",
+ "@typescript-eslint/no-use-before-define": "off",
+ "@typescript-eslint/no-object-literal-type-assertion": "off",
+ "@typescript-eslint/no-parameter-properties": "off"
+ },
+ "parserOptions": {
+ "sourceType": "module",
+ "ecmaFeatures": {
+ "jsx": false
+ }
+ },
+ "overrides": [
+ {
+ "files": [
+ "packages/eslint-plugin-tslint/**/*.ts",
+ "packages/eslint-plugin-typescript/**/*.js",
+ "packages/typescript-eslint-parser/**/*.ts",
+ "packages/typescript-estree/**/*.ts"
+ ],
+ "env": {
+ "jest/globals": true
+ },
+ "rules": {
+ "jest/no-disabled-tests": "warn",
+ "jest/no-focused-tests": "error",
+ "jest/no-identical-title": "error",
+ "jest/prefer-to-have-length": "warn",
+ "jest/valid-expect": "error"
+ }
+ },
+ {
+ "files": ["packages/eslint-plugin-typescript/**/*.js"],
+ "rules": {
+ "eslint-plugin/fixer-return": "error",
+ "eslint-plugin/no-identical-tests": "error",
+ "eslint-plugin/no-missing-placeholders": "error",
+ "eslint-plugin/no-unused-placeholders": "error",
+ "eslint-plugin/no-useless-token-range": "error",
+ "eslint-plugin/require-meta-fixable": "error",
+ "eslint-plugin/prefer-placeholders": "error",
+ "eslint-plugin/prefer-replace-text": "error",
+ "eslint-plugin/no-deprecated-report-api": "error",
+ "eslint-plugin/report-message-format": ["error", "^[A-Z'{].*[\\.}]$"],
+ "eslint-plugin/no-deprecated-context-methods": "error",
+ "eslint-plugin/prefer-output-null": "error",
+ "eslint-plugin/test-case-shorthand-strings": "error",
+ "eslint-plugin/require-meta-type": "error"
+ }
+ }
+ ]
+}
diff --git a/README.md b/README.md
index 2d6dda93ecb3..de2fdd5da6ae 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
Monorepo for all the tooling which enables ESLint to support TypeScript
-
+
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 63512b1f85ad..a34eaea0062d 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -21,6 +21,10 @@ jobs:
yarn check-format
displayName: 'Check code formatting'
+ - script: |
+ yarn lint
+ displayName: 'Run linting'
+
- script: |
yarn test
displayName: 'Run unit tests'
diff --git a/package.json b/package.json
index 5cb4261cb79a..ed6bbf422c9e 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,8 @@
"build": "lerna run build",
"clean": "lerna clean && lerna run clean",
"precommit": "yarn test && lint-staged",
+ "lint": "eslint . --ext .js,.ts",
+ "lint-fix": "eslint . --ext .js,.ts --fix",
"cz": "git-cz",
"commitmsg": "commitlint -E GIT_PARAMS",
"check-format": "prettier --list-different \"./**/*.{ts,js,json,md}\"",
@@ -63,6 +65,8 @@
"@types/semver": "^5.5.0",
"cz-conventional-changelog": "2.1.0",
"eslint": "^5.12.1",
+ "eslint-plugin-jest": "^22.1.3",
+ "eslint-plugin-eslint-plugin": "^2.0.1",
"glob": "7.1.2",
"husky": "0.14.3",
"jest": "23.6.0",
diff --git a/packages/eslint-plugin-tslint/README.md b/packages/eslint-plugin-tslint/README.md
index 7a1cdf297aa4..7eed5033dfbb 100644
--- a/packages/eslint-plugin-tslint/README.md
+++ b/packages/eslint-plugin-tslint/README.md
@@ -3,7 +3,7 @@
ESLint plugin wraps a TSLint configuration and lints the whole source using TSLint.
-
+
diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md
index b9366b302b31..ec96819a455f 100644
--- a/packages/eslint-plugin/README.md
+++ b/packages/eslint-plugin/README.md
@@ -1,7 +1,7 @@
ESLint Plugin TypeScript
-
+
diff --git a/packages/parser/README.md b/packages/parser/README.md
index 77359a790f34..f348ae4617dc 100644
--- a/packages/parser/README.md
+++ b/packages/parser/README.md
@@ -3,7 +3,7 @@
An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
-
+
diff --git a/packages/typescript-estree/README.md b/packages/typescript-estree/README.md
index 910002f4fae0..6769f0fca20b 100644
--- a/packages/typescript-estree/README.md
+++ b/packages/typescript-estree/README.md
@@ -3,7 +3,7 @@
A parser that converts TypeScript source code into an ESTree -compatible form
-
+
diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts
index 77336ee7b5f4..ee0a2b7d72f9 100644
--- a/packages/typescript-estree/tests/ast-alignment/utils.ts
+++ b/packages/typescript-estree/tests/ast-alignment/utils.ts
@@ -236,7 +236,7 @@ export function preprocessBabylonAST(ast: any): any {
* Babel: ClassProperty + abstract: true
* ts-estree: TSAbstractClassProperty
*/
- ClassProperty(node: any, parent: any) {
+ ClassProperty(node: any) {
if (node.abstract) {
node.type = 'TSAbstractClassProperty';
delete node.abstract;
diff --git a/yarn.lock b/yarn.lock
index c2cc9db7f6a2..a80ac0413712 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2333,6 +2333,16 @@ eslint-docs@^0.2.6:
ora "^3.0.0"
read-pkg-up "^4.0.0"
+eslint-plugin-eslint-plugin@^2.0.1:
+ version "2.0.1"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-eslint-plugin/-/eslint-plugin-eslint-plugin-2.0.1.tgz#d275434969dbde3da1d4cb7a121dc8d88457c786"
+ integrity sha512-kJ5TZsRJH/xYstG07v3YeOy/W5SDAEzV+bvvoL0aiG1HtqDmg4mJvNPnn/JngANMmsx8oXlJrIcBTCpJzm+9kg==
+
+eslint-plugin-jest@^22.1.3:
+ version "22.1.3"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.1.3.tgz#4444108dfcddc5d2117ed6dc551f529d7e73a99e"
+ integrity sha512-JTZTI6WQoNruAugNyCO8fXfTONVcDd5i6dMRFA5g3rUFn1UDDLILY1bTL6alvNXbW2U7Sc2OSpi8m08pInnq0A==
+
eslint-scope@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.0.tgz#50bf3071e9338bcdc43331794a0cb533f0136172"
From 193b434e5adc442ac4876f5aa8eda6d001cc72b6 Mon Sep 17 00:00:00 2001
From: Armano
Date: Mon, 21 Jan 2019 15:12:06 +0100
Subject: [PATCH 21/88] fix(eslint-plugin): improve detection of used vars in
heritage (#102)
---
.../eslint-plugin/lib/rules/no-unused-vars.js | 30 ++++++++-
.../tests/lib/rules/no-unused-vars.js | 65 +++++++++++++++++++
2 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/packages/eslint-plugin/lib/rules/no-unused-vars.js b/packages/eslint-plugin/lib/rules/no-unused-vars.js
index d7f32f15a5c1..bb09d6abd271 100644
--- a/packages/eslint-plugin/lib/rules/no-unused-vars.js
+++ b/packages/eslint-plugin/lib/rules/no-unused-vars.js
@@ -45,6 +45,25 @@ module.exports = Object.assign({}, baseRule, {
}
}
+ /**
+ * Mark heritage clause as used
+ * @param node The node currently being traversed
+ * @returns {void}
+ */
+ function markHeritageAsUsed(node) {
+ switch (node.type) {
+ case 'Identifier':
+ context.markVariableAsUsed(node.name);
+ break;
+ case 'MemberExpression':
+ markHeritageAsUsed(node.object);
+ break;
+ case 'CallExpression':
+ markHeritageAsUsed(node.callee);
+ break;
+ }
+ }
+
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
@@ -54,8 +73,15 @@ module.exports = Object.assign({}, baseRule, {
'TSTypeReference Identifier'(node) {
context.markVariableAsUsed(node.name);
},
- 'TSClassImplements Identifier'(node) {
- context.markVariableAsUsed(node.name);
+ TSInterfaceHeritage(node) {
+ if (node.expression) {
+ markHeritageAsUsed(node.expression);
+ }
+ },
+ TSClassImplements(node) {
+ if (node.expression) {
+ markHeritageAsUsed(node.expression);
+ }
},
'TSParameterProperty Identifier'(node) {
// just assume parameter properties are used
diff --git a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
index 25410bbf2701..c197adff8ee1 100644
--- a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
+++ b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
@@ -541,6 +541,15 @@ declare var Foo: {
new (value?: any): Object,
foo(): string
}
+ `,
+ `
+import foo from 'foo';
+export interface Bar extends foo.i18n {}
+ `,
+ `
+import foo from 'foo';
+import bar from 'foo';
+export interface Bar extends foo.i18n {}
`
],
@@ -763,6 +772,62 @@ enum FormFieldIds {
column: 6
}
]
+ },
+ {
+ code: `
+import test from 'test';
+import baz from 'baz';
+export interface Bar extends baz.test {}
+ `,
+ errors: [
+ {
+ message: "'test' is defined but never used.",
+ line: 2,
+ column: 8
+ }
+ ]
+ },
+ {
+ code: `
+import test from 'test';
+import baz from 'baz';
+export interface Bar extends baz().test {}
+ `,
+ errors: [
+ {
+ message: "'test' is defined but never used.",
+ line: 2,
+ column: 8
+ }
+ ]
+ },
+ {
+ code: `
+import test from 'test';
+import baz from 'baz';
+export class Bar implements baz.test {}
+ `,
+ errors: [
+ {
+ message: "'test' is defined but never used.",
+ line: 2,
+ column: 8
+ }
+ ]
+ },
+ {
+ code: `
+import test from 'test';
+import baz from 'baz';
+export class Bar implements baz().test {}
+ `,
+ errors: [
+ {
+ message: "'test' is defined but never used.",
+ line: 2,
+ column: 8
+ }
+ ]
}
]
});
From d12b63460d067ead3d9afa9d4f74dcada4b91196 Mon Sep 17 00:00:00 2001
From: James Henry
Date: Mon, 21 Jan 2019 10:20:30 -0500
Subject: [PATCH 22/88] chore: fix package names (#105)
---
.eslintrc.json | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/.eslintrc.json b/.eslintrc.json
index 6c87aaec59ad..f44790c843c8 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -30,8 +30,8 @@
{
"files": [
"packages/eslint-plugin-tslint/**/*.ts",
- "packages/eslint-plugin-typescript/**/*.js",
- "packages/typescript-eslint-parser/**/*.ts",
+ "packages/eslint-plugin/**/*.js",
+ "packages/parser/**/*.ts",
"packages/typescript-estree/**/*.ts"
],
"env": {
@@ -46,7 +46,7 @@
}
},
{
- "files": ["packages/eslint-plugin-typescript/**/*.js"],
+ "files": ["packages/eslint-plugin/**/*.js"],
"rules": {
"eslint-plugin/fixer-return": "error",
"eslint-plugin/no-identical-tests": "error",
From 34fbe628a78ece28eac75ef1c665de4c99505add Mon Sep 17 00:00:00 2001
From: James Henry
Date: Mon, 21 Jan 2019 18:41:14 -0500
Subject: [PATCH 23/88] test(typescript-estree): enable more alignment tests
(#114)
---
package.json | 2 +-
.../typescript-estree/src/semantic-errors.ts | 1 +
.../tests/ast-alignment/fixtures-to-test.ts | 69 +++----------------
.../semantic-diagnostics-enabled.ts.snap | 18 ++++-
yarn.lock | 8 +--
5 files changed, 31 insertions(+), 67 deletions(-)
diff --git a/package.json b/package.json
index ed6bbf422c9e..c7a27e9a643d 100644
--- a/package.json
+++ b/package.json
@@ -52,7 +52,7 @@
},
"devDependencies": {
"@babel/code-frame": "7.0.0",
- "@babel/parser": "7.2.3",
+ "@babel/parser": "7.3.0",
"@commitlint/cli": "^7.1.2",
"@commitlint/config-conventional": "^7.1.2",
"@commitlint/travis-cli": "^7.1.2",
diff --git a/packages/typescript-estree/src/semantic-errors.ts b/packages/typescript-estree/src/semantic-errors.ts
index 22e8210ba55d..169031947d3f 100644
--- a/packages/typescript-estree/src/semantic-errors.ts
+++ b/packages/typescript-estree/src/semantic-errors.ts
@@ -54,6 +54,7 @@ function whitelistSupportedDiagnostics(
): ReadonlyArray {
return diagnostics.filter(diagnostic => {
switch (diagnostic.code) {
+ case 1013: // ts 3.2 "A rest parameter or binding pattern may not have a trailing comma."
case 1014: // ts 3.2 "A rest parameter must be last in a parameter list."
case 1044: // ts 3.2 "'{0}' modifier cannot appear on a module or namespace element."
case 1045: // ts 3.2 "A '{0}' modifier cannot be used with an interface declaration."
diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
index 178b86573537..2e478b0fb1b1 100644
--- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
+++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
@@ -147,14 +147,7 @@ tester.addFixturePatternConfig('javascript/simple-literals');
tester.addFixturePatternConfig('javascript/directives');
-tester.addFixturePatternConfig('javascript/experimentalObjectRestSpread', {
- ignore: [
- /**
- * Trailing comma is not permitted after a "RestElement" in Babel
- */
- 'invalid-rest-trailing-comma'
- ]
-});
+tester.addFixturePatternConfig('javascript/experimentalObjectRestSpread');
tester.addFixturePatternConfig('javascript/arrowFunctions', {
ignore: [
@@ -330,16 +323,6 @@ tester.addFixturePatternConfig('typescript/basics', {
* TODO: Investigate in more depth, potentially split up different parts of the interface
*/
'interface-with-all-property-types', // babel parse errors
- /**
- * PR for generic ArrowFunctionExpression ranges has been merged into Babel: https://github.com/babel/babel/pull/9295
- * TODO: remove me in next babel > 7.2.3
- */
- 'arrow-function-with-type-parameters',
- /**
- * PR for this type predicate ranges has been merged into Babel: https://github.com/babel/babel/pull/9339
- * TODO: remove me in next babel > 7.2.3
- */
- 'type-guard-in-method',
/**
* there is difference in range between babel and ts-estree
*/
@@ -351,11 +334,6 @@ tester.addFixturePatternConfig('typescript/basics', {
* TODO: report it to babel
*/
'interface-with-extends-member-expression',
- /**
- * PR for parsing exported abstract interface has been merged into Babel: https://github.com/babel/babel/pull/9336
- * TODO: remove me in next babel > 7.2.3
- */
- 'abstract-interface',
/**
* Babel bug for optional or abstract methods
* https://github.com/babel/babel/issues/9305
@@ -364,46 +342,32 @@ tester.addFixturePatternConfig('typescript/basics', {
'abstract-class-with-optional-method', // babel parse errors
'declare-class-with-optional-method', // babel parse errors
/**
- * PR for parameter property ranges has been merged into Babel: https://github.com/babel/babel/pull/9284
- * TODO: remove me in next babel > 7.2.3
+ * Was expected to be fixed by PR into Babel: https://github.com/babel/babel/pull/9284
+ * But not fixed in Babel 7.3
+ * TODO: Investigate differences
*/
'class-with-private-parameter-properties',
'class-with-protected-parameter-properties',
'class-with-public-parameter-properties',
'class-with-readonly-parameter-properties',
/**
- * PR for type import has been merged into Babel: https://github.com/babel/babel/pull/9302
- * TODO: remove me in next babel > 7.2.3
+ * Was expected to be fixed by PR into Babel: https://github.com/babel/babel/pull/9302
+ * But not fixed in Babel 7.3
+ * TODO: Investigate differences
*/
'import-type',
'import-type-with-type-parameters-in-type-reference',
- /**
- * PR for BigInt support has been merged into Babel: https://github.com/babel/babel/pull/9230
- * TODO: remove me in next babel > 7.2.3
- */
- 'typed-keyword-bigint',
/**
* Not yet supported in Babel https://github.com/babel/babel/issues/9228
* Directive field is not added to module and namespace
*/
'directive-in-module',
'directive-in-namespace',
- /**
- * PR for type assertions ranges has been merged into Babel: https://github.com/babel/babel/pull/9284
- * TODO: remove me in next babel > 7.2.3
- */
- 'type-assertion',
/**
* Babel parses this incorrectly
* https://github.com/babel/babel/issues/9324
*/
- 'type-assertion-arrow-function',
- /**
- * PR for type parsing declare and abstract classes has been merged into Babel: https://github.com/babel/babel/pull/9328
- * TODO: remove me in next babel > 7.2.3
- */
- 'class-multi-line-keyword-declare',
- 'class-multi-line-keyword-abstract'
+ 'type-assertion-arrow-function'
],
ignoreSourceType: [
/**
@@ -443,27 +407,12 @@ tester.addFixturePatternConfig('typescript/expressions', {
});
tester.addFixturePatternConfig('typescript/errorRecovery', {
- fileType: 'ts',
- ignore: [
- /**
- * PR with errors in empty extends and implements has been merged into Babel: https://github.com/babel/babel/pull/9292
- * TODO: remove me in next babel > 7.2.3
- */
- 'interface-empty-extends',
- 'class-extends-empty-implements'
- ]
+ fileType: 'ts'
});
tester.addFixturePatternConfig('typescript/types', {
fileType: 'ts',
ignore: [
- /**
- * PR for type Identifier in TSIndexSignature ranges has been merged into Babel: https://github.com/babel/babel/pull/9335
- * TODO: remove me in next babel > 7.2.3
- */
- 'index-signature',
- 'index-signature-readonly',
- 'index-signature-without-type',
/**
* AST difference
*/
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
index 3407f292ace2..dfd7dbf783d0 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
@@ -560,7 +560,14 @@ Object {
}
`;
-exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/destructuring-and-spread/invalid-not-final-array-empty.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/destructuring-and-spread/invalid-not-final-array-empty.src 1`] = `
+Object {
+ "column": 5,
+ "index": 5,
+ "lineNumber": 1,
+ "message": "A rest parameter or binding pattern may not have a trailing comma.",
+}
+`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/destructuring-and-spread/multi-destructured.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
@@ -622,7 +629,14 @@ Object {
}
`;
-exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/experimentalObjectRestSpread/invalid-rest-trailing-comma.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/experimentalObjectRestSpread/invalid-rest-trailing-comma.src 1`] = `
+Object {
+ "column": 16,
+ "index": 16,
+ "lineNumber": 1,
+ "message": "A rest parameter or binding pattern may not have a trailing comma.",
+}
+`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/experimentalObjectRestSpread/object-rest.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
diff --git a/yarn.lock b/yarn.lock
index a80ac0413712..e2d917cdc557 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -18,10 +18,10 @@
esutils "^2.0.2"
js-tokens "^4.0.0"
-"@babel/parser@7.2.3":
- version "7.2.3"
- resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.2.3.tgz#32f5df65744b70888d17872ec106b02434ba1489"
- integrity sha512-0LyEcVlfCoFmci8mXx8A5oIkpkOgyo8dRHtxBnK9RRBwxO2+JZPNsqtVEZQ7mJFPxnXF9lfmU24mHOPI0qnlkA==
+"@babel/parser@7.3.0":
+ version "7.3.0"
+ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.3.0.tgz#930251fe6714df47ce540a919ccdf6dcfb652b61"
+ integrity sha512-8M30TzMpLHGmuthHZStm4F+az5wxyYeh8U+LWK7+b2qnlQ0anXBmOQ1I8DCMV1K981wPY3C3kWZ4SA1lR3Y3xQ==
"@commitlint/cli@^7.1.2", "@commitlint/cli@^7.3.2":
version "7.3.2"
From 857cdc004da8851ce8c634d6e1d02eb0cdf82b37 Mon Sep 17 00:00:00 2001
From: Armano
Date: Tue, 22 Jan 2019 01:09:17 +0100
Subject: [PATCH 24/88] refactor(typescript-estree): correct warnings reported
by sonarlint (#100)
---
.../typescript-estree/src/ast-converter.ts | 6 +-
packages/typescript-estree/src/convert.ts | 8 +-
packages/typescript-estree/src/parser.ts | 4 +-
.../tests/lib/__snapshots__/parse.ts.snap | 80 +++++++++++++++++++
packages/typescript-estree/tests/lib/parse.ts | 62 +++++++++++++-
.../typescript-estree/tools/test-utils.ts | 1 +
6 files changed, 147 insertions(+), 14 deletions(-)
diff --git a/packages/typescript-estree/src/ast-converter.ts b/packages/typescript-estree/src/ast-converter.ts
index ce6f14b63f71..13d2212c5c4f 100644
--- a/packages/typescript-estree/src/ast-converter.ts
+++ b/packages/typescript-estree/src/ast-converter.ts
@@ -11,11 +11,11 @@ import { convertTokens } from './node-utils';
import ts from 'typescript';
import { Extra } from './temp-types-based-on-js-source';
-export default (
+export default function astConverter(
ast: ts.SourceFile,
extra: Extra,
shouldProvideParserServices: boolean
-) => {
+) {
/**
* The TypeScript compiler produced fundamental parse errors when parsing the
* source.
@@ -59,4 +59,4 @@ export default (
}
return { estree, astMaps };
-};
+}
diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts
index f75547953df8..5d3c4df99734 100644
--- a/packages/typescript-estree/src/convert.ts
+++ b/packages/typescript-estree/src/convert.ts
@@ -694,8 +694,8 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
}
if (node.type) {
- (result as any).id.typeAnnotation = convertTypeAnnotation(node.type);
- fixTypeAnnotationParentLocation((result as any).id);
+ result.id!.typeAnnotation = convertTypeAnnotation(node.type);
+ fixTypeAnnotationParentLocation(result.id!);
}
break;
}
@@ -1249,7 +1249,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
expressions: []
});
- node.templateSpans.forEach((templateSpan: any) => {
+ node.templateSpans.forEach(templateSpan => {
(result as any).expressions.push(convertChild(templateSpan.expression));
(result as any).quasis.push(convertChild(templateSpan.literal));
});
@@ -1333,7 +1333,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
}
if (node.questionToken) {
- (parameter as any).optional = true;
+ parameter.optional = true;
}
if (node.modifiers) {
diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts
index 2f6347e0a7a2..ff2784aa9963 100644
--- a/packages/typescript-estree/src/parser.ts
+++ b/packages/typescript-estree/src/parser.ts
@@ -213,10 +213,8 @@ function generateAST(
tsNodeToESTreeNodeMap?: WeakMap;
};
} {
- const toString = String;
-
if (typeof code !== 'string' && !((code as any) instanceof String)) {
- code = toString(code);
+ code = String(code);
}
resetExtra();
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap
index ae6a9a339e17..4509f7441037 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap
@@ -188,3 +188,83 @@ Object {
"type": "Program",
}
`;
+
+exports[`parse() non string code should correctly convert code to string 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "expression": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "raw": "12345",
+ "type": "Literal",
+ "value": 12345,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "type": "ExpressionStatement",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "sourceType": "script",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "type": "Numeric",
+ "value": "12345",
+ },
+ ],
+ "type": "Program",
+}
+`;
diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts
index cbb9bebfd052..74f02d03792c 100644
--- a/packages/typescript-estree/tests/lib/parse.ts
+++ b/packages/typescript-estree/tests/lib/parse.ts
@@ -6,6 +6,7 @@
* MIT License
*/
import * as parser from '../../src/parser';
+import * as astConverter from '../../src/ast-converter';
import { ParserOptions } from '../../src/temp-types-based-on-js-source';
import { createSnapshotTestBlock } from '../../tools/test-utils';
@@ -16,8 +17,8 @@ import { createSnapshotTestBlock } from '../../tools/test-utils';
describe('parse()', () => {
describe('basic functionality', () => {
it('should parse an empty string', () => {
- expect((parser as any).parse('').body).toEqual([]);
- expect(parser.parse('', {} as any).body).toEqual([]);
+ expect(parser.parse('').body).toEqual([]);
+ expect(parser.parse('', {}).body).toEqual([]);
});
});
@@ -33,7 +34,7 @@ describe('parse()', () => {
describe('general', () => {
const code = 'let foo = bar;';
- const config = {
+ const config: ParserOptions = {
comment: true,
tokens: true,
range: true,
@@ -42,7 +43,60 @@ describe('parse()', () => {
it(
'output tokens, comments, locs, and ranges when called with those options',
- createSnapshotTestBlock(code, config as ParserOptions)
+ createSnapshotTestBlock(code, config)
);
});
+
+ describe('non string code', () => {
+ const code = (12345 as any) as string;
+ const config: ParserOptions = {
+ comment: true,
+ tokens: true,
+ range: true,
+ loc: true
+ };
+
+ it(
+ 'should correctly convert code to string',
+ createSnapshotTestBlock(code, config)
+ );
+ });
+
+ describe('loggerFn should be propagated to ast-converter', () => {
+ it('output tokens, comments, locs, and ranges when called with those options', () => {
+ const spy = jest.spyOn(astConverter, 'default');
+
+ const loggerFn = jest.fn(() => true);
+
+ parser.parse('let foo = bar;', {
+ loggerFn,
+ comment: true,
+ tokens: true,
+ range: true,
+ loc: true
+ });
+
+ expect(spy).toHaveBeenCalledWith(
+ jasmine.any(Object),
+ {
+ code: 'let foo = bar;',
+ comment: true,
+ comments: [],
+ errorOnTypeScriptSyntacticAndSemanticIssues: false,
+ errorOnUnknownASTType: false,
+ extraFileExtensions: [],
+ jsx: false,
+ loc: true,
+ log: loggerFn,
+ projects: [],
+ range: true,
+ strict: false,
+ tokens: jasmine.any(Array),
+ tsconfigRootDir: jasmine.any(String),
+ useJSXTextNode: false
+ },
+ false
+ );
+ });
+ });
});
diff --git a/packages/typescript-estree/tools/test-utils.ts b/packages/typescript-estree/tools/test-utils.ts
index dc507d78e1e8..9191ae5e518a 100644
--- a/packages/typescript-estree/tools/test-utils.ts
+++ b/packages/typescript-estree/tools/test-utils.ts
@@ -36,6 +36,7 @@ export function parseCodeAndGenerateServices(
* and which performs an assertion on the snapshot for the given code and config.
* @param {string} code The source code to parse
* @param {ParserOptions} config the parser configuration
+ * @param {boolean} generateServices Flag determining whether to generate ast maps and program or not
* @returns {jest.ProvidesCallback} callback for Jest it() block
*/
export function createSnapshotTestBlock(
From e0f409390cbedc57aa1ed38ce8118979cd8db35b Mon Sep 17 00:00:00 2001
From: James Henry
Date: Mon, 21 Jan 2019 19:26:38 -0500
Subject: [PATCH 25/88] build: try example canary conditional job (#116)
---
azure-pipelines.yml | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index a34eaea0062d..11634775f519 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -64,3 +64,20 @@ jobs:
- script: |
yarn test
displayName: 'Run unit tests'
+
+ - job: publish_canary_version
+ displayName: Publish the latest code as a canary version
+ dependsOn:
+ - primary_code_validation_and_tests
+ - unit_tests_on_other_node_versions
+ condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'master'), ne(variables['Build.Reason'], 'PullRequest'))
+ pool:
+ vmImage: 'Ubuntu-16.04'
+ steps:
+ - task: NodeTool@0
+ inputs:
+ versionSpec: 11
+ displayName: 'Install Node.js 11'
+
+ - script: |
+ echo "canary"
From 33ac99fbc60ee80774f0d7a415015d33e764bec3 Mon Sep 17 00:00:00 2001
From: James Henry
Date: Mon, 21 Jan 2019 19:41:10 -0500
Subject: [PATCH 26/88] build: publish all packages in canary job (#117)
---
azure-pipelines.yml | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 11634775f519..c933f0827920 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -80,4 +80,10 @@ jobs:
displayName: 'Install Node.js 11'
- script: |
- echo "canary"
+ # This also runs a build as part of the postinstall
+ # bootstrap
+ yarn --ignore-engines --frozen-lockfile
+
+ - script: |
+ npx lerna publish --canary --exact --force-publish --yes
+ displayName: 'Publish all packages to npm'
From 819b640559bb41d43467dd473ee15eaf227247ba Mon Sep 17 00:00:00 2001
From: James Henry
Date: Mon, 21 Jan 2019 19:55:45 -0500
Subject: [PATCH 27/88] build: npm auth
---
azure-pipelines.yml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index c933f0827920..805b5c0a1ee9 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -84,6 +84,9 @@ jobs:
# bootstrap
yarn --ignore-engines --frozen-lockfile
+ - script: |
+ npm config set //registry.npmjs.org/:_authToken=$(NPM_TOKEN)
+
- script: |
npx lerna publish --canary --exact --force-publish --yes
displayName: 'Publish all packages to npm'
From 5841cd2eca6a2b2a4fc018fa71b5f7ef121c4dab Mon Sep 17 00:00:00 2001
From: Jed Fox
Date: Tue, 22 Jan 2019 07:38:55 -0500
Subject: [PATCH 28/88] =?UTF-8?q?fix(eslint-plugin):=20don=E2=80=99t=20mar?=
=?UTF-8?q?k=20`declare=20class`=20as=20unused=20(#110)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
fixes #106
---
packages/eslint-plugin/lib/rules/no-unused-vars.js | 6 ++++++
packages/eslint-plugin/tests/lib/rules/no-unused-vars.js | 7 +++++++
2 files changed, 13 insertions(+)
diff --git a/packages/eslint-plugin/lib/rules/no-unused-vars.js b/packages/eslint-plugin/lib/rules/no-unused-vars.js
index bb09d6abd271..79c60d437c24 100644
--- a/packages/eslint-plugin/lib/rules/no-unused-vars.js
+++ b/packages/eslint-plugin/lib/rules/no-unused-vars.js
@@ -92,6 +92,12 @@ module.exports = Object.assign({}, baseRule, {
},
'*[declare=true] Identifier'(node) {
context.markVariableAsUsed(node.name);
+ const scope = context.getScope();
+ const { variableScope } = scope;
+ if (variableScope !== scope) {
+ const superVar = variableScope.set.get(node.name);
+ if (superVar) superVar.eslintUsed = true;
+ }
}
});
}
diff --git a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
index c197adff8ee1..726f755c3956 100644
--- a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
+++ b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
@@ -540,6 +540,13 @@ declare namespace Foo {
declare var Foo: {
new (value?: any): Object,
foo(): string
+}
+ `,
+ // https://github.com/typescript-eslint/typescript-eslint/issues/106
+ `
+declare class Foo {
+ constructor(value?: any): Object;
+ foo(): string;
}
`,
`
From 4e781f1844acb3c74b093b1380cc37172cac2bfe Mon Sep 17 00:00:00 2001
From: Armano
Date: Tue, 22 Jan 2019 16:28:56 +0100
Subject: [PATCH 29/88] fix(typescript-estree): fix range of assignment in
parameter (#115)
---
.../lib/__snapshots__/typescript.ts.snap | 28 +++++++++----------
packages/typescript-estree/src/convert.ts | 6 ++++
packages/typescript-estree/src/node-utils.ts | 2 +-
.../tests/ast-alignment/fixtures-to-test.ts | 9 ------
.../lib/__snapshots__/typescript.ts.snap | 28 +++++++++----------
5 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
index b1013b958c11..046f4e2081a2 100644
--- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
@@ -21333,12 +21333,12 @@ Object {
"line": 4,
},
"start": Object {
- "column": 14,
+ "column": 22,
"line": 4,
},
},
"range": Array [
- 116,
+ 124,
140,
],
"right": Object {
@@ -21439,12 +21439,12 @@ Object {
"line": 5,
},
"start": Object {
- "column": 14,
+ "column": 31,
"line": 5,
},
},
"range": Array [
- 156,
+ 173,
197,
],
"right": Object {
@@ -24453,12 +24453,12 @@ Object {
"line": 4,
},
"start": Object {
- "column": 14,
+ "column": 24,
"line": 4,
},
},
"range": Array [
- 120,
+ 130,
146,
],
"right": Object {
@@ -24559,12 +24559,12 @@ Object {
"line": 5,
},
"start": Object {
- "column": 14,
+ "column": 33,
"line": 5,
},
},
"range": Array [
- 162,
+ 181,
205,
],
"right": Object {
@@ -25579,12 +25579,12 @@ Object {
"line": 4,
},
"start": Object {
- "column": 14,
+ "column": 21,
"line": 4,
},
},
"range": Array [
- 114,
+ 121,
137,
],
"right": Object {
@@ -25685,12 +25685,12 @@ Object {
"line": 5,
},
"start": Object {
- "column": 14,
+ "column": 30,
"line": 5,
},
},
"range": Array [
- 153,
+ 169,
193,
],
"right": Object {
@@ -26633,12 +26633,12 @@ Object {
"line": 3,
},
"start": Object {
- "column": 14,
+ "column": 23,
"line": 3,
},
},
"range": Array [
- 68,
+ 77,
103,
],
"right": Object {
diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts
index 5d3c4df99734..c02a2eece24a 100644
--- a/packages/typescript-estree/src/convert.ts
+++ b/packages/typescript-estree/src/convert.ts
@@ -1318,6 +1318,12 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
left: parameter,
right: convertChild(node.initializer)
});
+
+ if (node.modifiers) {
+ // AssignmentPattern should not contain modifiers in range
+ result.range[0] = parameter.range[0];
+ result.loc = getLocFor(result.range[0], result.range[1], ast);
+ }
} else {
parameter = result = convert({
node: node.name,
diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts
index 678c97215fa0..fa780cfe8e97 100644
--- a/packages/typescript-estree/src/node-utils.ts
+++ b/packages/typescript-estree/src/node-utils.ts
@@ -161,7 +161,7 @@ export function hasModifier(
* @param node TypeScript AST node
* @returns returns last modifier if present or null
*/
-export function getLastModifier(node: ts.Node): ts.Node | null {
+export function getLastModifier(node: ts.Node): ts.Modifier | null {
return (
(!!node.modifiers &&
!!node.modifiers.length &&
diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
index 2e478b0fb1b1..3b1a21e43d80 100644
--- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
+++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
@@ -341,15 +341,6 @@ tester.addFixturePatternConfig('typescript/basics', {
'abstract-class-with-abstract-method', // babel parse errors
'abstract-class-with-optional-method', // babel parse errors
'declare-class-with-optional-method', // babel parse errors
- /**
- * Was expected to be fixed by PR into Babel: https://github.com/babel/babel/pull/9284
- * But not fixed in Babel 7.3
- * TODO: Investigate differences
- */
- 'class-with-private-parameter-properties',
- 'class-with-protected-parameter-properties',
- 'class-with-public-parameter-properties',
- 'class-with-readonly-parameter-properties',
/**
* Was expected to be fixed by PR into Babel: https://github.com/babel/babel/pull/9302
* But not fixed in Babel 7.3
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
index 5ad5989309a8..6341ffcd7d74 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
@@ -21291,12 +21291,12 @@ Object {
"line": 4,
},
"start": Object {
- "column": 14,
+ "column": 22,
"line": 4,
},
},
"range": Array [
- 116,
+ 124,
140,
],
"right": Object {
@@ -21397,12 +21397,12 @@ Object {
"line": 5,
},
"start": Object {
- "column": 14,
+ "column": 31,
"line": 5,
},
},
"range": Array [
- 156,
+ 173,
197,
],
"right": Object {
@@ -24408,12 +24408,12 @@ Object {
"line": 4,
},
"start": Object {
- "column": 14,
+ "column": 24,
"line": 4,
},
},
"range": Array [
- 120,
+ 130,
146,
],
"right": Object {
@@ -24514,12 +24514,12 @@ Object {
"line": 5,
},
"start": Object {
- "column": 14,
+ "column": 33,
"line": 5,
},
},
"range": Array [
- 162,
+ 181,
205,
],
"right": Object {
@@ -25533,12 +25533,12 @@ Object {
"line": 4,
},
"start": Object {
- "column": 14,
+ "column": 21,
"line": 4,
},
},
"range": Array [
- 114,
+ 121,
137,
],
"right": Object {
@@ -25639,12 +25639,12 @@ Object {
"line": 5,
},
"start": Object {
- "column": 14,
+ "column": 30,
"line": 5,
},
},
"range": Array [
- 153,
+ 169,
193,
],
"right": Object {
@@ -26586,12 +26586,12 @@ Object {
"line": 3,
},
"start": Object {
- "column": 14,
+ "column": 23,
"line": 3,
},
},
"range": Array [
- 68,
+ 77,
103,
],
"right": Object {
From c541edec85372e1d3e9f424365569f12f6b5690d Mon Sep 17 00:00:00 2001
From: Armano
Date: Tue, 22 Jan 2019 17:38:44 +0100
Subject: [PATCH 30/88] feat(eslint-plugin): add new rule
restrict-plus-operands (#70)
---
packages/eslint-plugin/README.md | 1 +
.../docs/rules/restrict-plus-operands.md | 25 ++
.../lib/rules/restrict-plus-operands.js | 104 +++++++
.../tests/fixtures/tsconfig.json | 9 +
.../tests/lib/rules/restrict-plus-operands.js | 282 ++++++++++++++++++
5 files changed, 421 insertions(+)
create mode 100644 packages/eslint-plugin/docs/rules/restrict-plus-operands.md
create mode 100644 packages/eslint-plugin/lib/rules/restrict-plus-operands.js
create mode 100644 packages/eslint-plugin/tests/fixtures/tsconfig.json
create mode 100644 packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js
diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md
index ec96819a455f..108dd0f994be 100644
--- a/packages/eslint-plugin/README.md
+++ b/packages/eslint-plugin/README.md
@@ -93,6 +93,7 @@ You can also enable all the recommended rules at once. Add `plugin:@typescript-e
| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements (`no-var-requires` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/prefer-interface`](./docs/rules/prefer-interface.md) | Prefer an interface declaration over a type literal (type T = { ... }) (`interface-over-type-literal` from TSLint) | :heavy_check_mark: | :wrench: |
| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (`no-internal-module` from TSLint) | :heavy_check_mark: | :wrench: |
+| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string. (`restrict-plus-operands` from TSLint) | | |
| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations (`typedef-whitespace` from TSLint) | :heavy_check_mark: | :wrench: |
diff --git a/packages/eslint-plugin/docs/rules/restrict-plus-operands.md b/packages/eslint-plugin/docs/rules/restrict-plus-operands.md
new file mode 100644
index 000000000000..a1436daf7695
--- /dev/null
+++ b/packages/eslint-plugin/docs/rules/restrict-plus-operands.md
@@ -0,0 +1,25 @@
+# When adding two variables, operands must both be of type number or of type string. (restrict-plus-operands)
+
+Examples of **correct** code:
+
+```ts
+var foo = parseInt('5.5', 10) + 10;
+```
+
+Examples of **incorrect** code:
+
+```ts
+var foo = '5.5' + 5;
+```
+
+## Options
+
+```json
+{
+ "@typescript-eslint/restrict-plus-operands": "error"
+}
+```
+
+## Compatibility
+
+- TSLint: [restrict-plus-operands](https://palantir.github.io/tslint/rules/restrict-plus-operands/)
diff --git a/packages/eslint-plugin/lib/rules/restrict-plus-operands.js b/packages/eslint-plugin/lib/rules/restrict-plus-operands.js
new file mode 100644
index 000000000000..222f51e5c8af
--- /dev/null
+++ b/packages/eslint-plugin/lib/rules/restrict-plus-operands.js
@@ -0,0 +1,104 @@
+/**
+ * @fileoverview When adding two variables, operands must both be of type number or of type string.
+ * @author James Henry
+ * @author Armano
+ */
+'use strict';
+
+const util = require('../util');
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+module.exports = {
+ meta: {
+ type: 'problem',
+ docs: {
+ description:
+ 'When adding two variables, operands must both be of type number or of type string.',
+ extraDescription: [util.tslintRule('restrict-plus-operands')],
+ category: 'TypeScript',
+ url: util.metaDocsUrl('restrict-plus-operands')
+ },
+ messages: {
+ notNumbers:
+ "Operands of '+' operation must either be both strings or both numbers.",
+ notStrings:
+ "Operands of '+' operation must either be both strings or both numbers. Consider using a template literal."
+ },
+ schema: []
+ },
+
+ create(context) {
+ const service = util.getParserServices(context);
+
+ const typeChecker = service.program.getTypeChecker();
+
+ /**
+ * Helper function to get base type of node
+ * @param {ts.Type} type type to be evaluated
+ * @returns {*} string, number or invalid
+ */
+ function getBaseTypeOfLiteralType(type) {
+ if (type.isNumberLiteral()) {
+ return 'number';
+ }
+ if (type.isStringLiteral()) {
+ return 'string';
+ }
+ if (type.isUnion()) {
+ const types = type.types.map(getBaseTypeOfLiteralType);
+
+ return types.every(value => value === types[0]) ? types[0] : 'invalid';
+ }
+
+ const stringType = typeChecker.typeToString(type);
+
+ if (stringType === 'number' || stringType === 'string') {
+ return stringType;
+ }
+ return 'invalid';
+ }
+
+ /**
+ * Helper function to get base type of node
+ * @param {ASTNode} node the node to be evaluated.
+ * @returns {*} string, number or invalid
+ */
+ function getNodeType(node) {
+ const tsNode = service.esTreeNodeToTSNodeMap.get(node);
+ const type = typeChecker.getTypeAtLocation(tsNode);
+
+ return getBaseTypeOfLiteralType(type);
+ }
+
+ //----------------------------------------------------------------------
+ // Public
+ //----------------------------------------------------------------------
+ return {
+ "BinaryExpression[operator='+']"(node) {
+ const leftType = getNodeType(node.left);
+ const rightType = getNodeType(node.right);
+
+ if (
+ leftType === 'invalid' ||
+ rightType === 'invalid' ||
+ leftType !== rightType
+ ) {
+ if (leftType === 'string' || rightType === 'string') {
+ context.report({
+ node,
+ messageId: 'notStrings'
+ });
+ } else {
+ context.report({
+ node,
+ messageId: 'notNumbers'
+ });
+ }
+ }
+ }
+ };
+ }
+};
diff --git a/packages/eslint-plugin/tests/fixtures/tsconfig.json b/packages/eslint-plugin/tests/fixtures/tsconfig.json
new file mode 100644
index 000000000000..8702b63472ba
--- /dev/null
+++ b/packages/eslint-plugin/tests/fixtures/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "compilerOptions": {
+ "target": "es5",
+ "module": "commonjs",
+ "strict": true,
+ "esModuleInterop": true,
+ "lib": ["es2015", "es2017"]
+ }
+}
diff --git a/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js b/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js
new file mode 100644
index 000000000000..a13b7cea3e47
--- /dev/null
+++ b/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js
@@ -0,0 +1,282 @@
+/**
+ * @fileoverview When adding two variables, operands must both be of type number or of type string.
+ * @author James Henry
+ * @author Armano
+ */
+'use strict';
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+const path = require('path');
+
+const rule = require('../../../lib/rules/restrict-plus-operands'),
+ RuleTester = require('eslint').RuleTester;
+
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
+const rootPath = path.join(process.cwd(), 'tests/fixtures/');
+
+const ruleTester = new RuleTester({
+ parser: '@typescript-eslint/parser',
+ parserOptions: {
+ generateServices: true,
+ tsconfigRootDir: rootPath,
+ project: './tsconfig.json'
+ }
+});
+
+ruleTester.run('restrict-plus-operands', rule, {
+ valid: [
+ `var x = 5;`,
+ `var y = "10";`,
+ `var z = 8.2;`,
+ `var w = "6.5";`,
+ `var foo = 5 + 10;`,
+ `var foo = "5.5" + "10";`,
+ `var foo = parseInt("5.5", 10) + 10;`,
+ `var foo = parseFloat("5.5", 10) + 10;`,
+ `
+function test () : number { return 2; }
+var foo = test("5.5", 10) + 10;
+ `,
+ `
+var x = 5;
+var z = 8.2;
+var foo = x + z;
+ `,
+ `
+var w = "6.5";
+var y = "10";
+var foo = y + w;
+ `,
+ 'var foo = 1 + 1;',
+ "var foo = '1' + '1';",
+ `
+var pair: { first: number, second: string } = { first: 5, second: "10" };
+var foo = pair.first + 10;
+ `,
+ `
+var pair: { first: number, second: string } = { first: 5, second: "10" };
+var foo = pair.first + (10 as number);
+ `,
+ `
+var pair: { first: number, second: string } = { first: 5, second: "10" };
+var foo = "5.5" + pair.second;
+ `,
+ `
+var pair: { first: number, second: string } = { first: 5, second: "10" };
+var foo = ("5.5" as string) + pair.second;
+ `,
+ `const foo = 'hello' + (someBoolean ? 'a' : 'b') + (() => someBoolean ? 'c' : 'd')() + 'e';`,
+ `const balls = true;`,
+ `balls === true;`
+ ],
+ invalid: [
+ {
+ code: "var foo = '1' + 1;",
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: 'var foo = [] + {};',
+ errors: [
+ {
+ messageId: 'notNumbers',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `var foo = 5 + "10";`,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `var foo = [] + 5;`,
+ errors: [
+ {
+ messageId: 'notNumbers',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `var foo = [] + {};`,
+ errors: [
+ {
+ messageId: 'notNumbers',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `var foo = [] + [];`,
+ errors: [
+ {
+ messageId: 'notNumbers',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `var foo = 5 + [];`,
+ errors: [
+ {
+ messageId: 'notNumbers',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `var foo = "5" + {};`,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `var foo = 5.5 + "5";`,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `var foo = "5.5" + 5;`,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `
+var x = 5;
+var y = "10";
+var foo = x + y;
+ `,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 4,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `
+var x = 5;
+var y = "10";
+var foo = y + x;
+ `,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 4,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `
+var x = 5;
+var foo = x + {};
+ `,
+ errors: [
+ {
+ messageId: 'notNumbers',
+ line: 3,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `
+var y = "10";
+var foo = [] + y;
+ `,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 3,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `
+var pair: { first: number, second: string } = { first: 5, second: "10" };
+var foo = pair.first + "10";
+ `,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 3,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `
+var pair: { first: number, second: string } = { first: 5, second: "10" };
+var foo = 5 + pair.second;
+ `,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 3,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `var foo = parseInt("5.5", 10) + "10";`,
+ errors: [
+ {
+ messageId: 'notStrings',
+ line: 1,
+ column: 11
+ }
+ ]
+ },
+ {
+ code: `
+var pair = { first: 5, second: "10" };
+var foo = pair + pair;
+ `,
+ errors: [
+ {
+ messageId: 'notNumbers',
+ line: 3,
+ column: 11
+ }
+ ]
+ }
+ ]
+});
From 74802b1b9b051c94a220fc5859b64211c7c71d7c Mon Sep 17 00:00:00 2001
From: Armano
Date: Wed, 23 Jan 2019 00:28:07 +0100
Subject: [PATCH 31/88] refactor(typescript-estree): simplify range calculation
for body nodes (#127)
---
.../lib/__snapshots__/javascript.ts.snap | 2 +
.../lib/__snapshots__/typescript.ts.snap | 2 +
.../classes/class-with-no-body.src.js | 1 +
.../interface-with-no-body.src.ts | 1 +
packages/typescript-estree/src/convert.ts | 69 +++----------------
packages/typescript-estree/src/node-utils.ts | 4 +-
.../lib/__snapshots__/javascript.ts.snap | 2 +
.../semantic-diagnostics-enabled.ts.snap | 18 +++++
.../lib/__snapshots__/typescript.ts.snap | 2 +
9 files changed, 41 insertions(+), 60 deletions(-)
create mode 100644 packages/shared-fixtures/fixtures/javascript/classes/class-with-no-body.src.js
create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/interface-with-no-body.src.ts
diff --git a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap
index fcbb463e5ee9..b31c5e710a2b 100644
--- a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap
@@ -30326,6 +30326,8 @@ Object {
}
`;
+exports[`javascript fixtures/classes/class-with-no-body.src 1`] = `"'{' expected."`;
+
exports[`javascript fixtures/classes/derived-class-assign-to-var.src 1`] = `
Object {
"body": Array [
diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
index 046f4e2081a2..cd9460af3e32 100644
--- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
@@ -95244,6 +95244,8 @@ Object {
}
`;
+exports[`typescript fixtures/errorRecovery/interface-with-no-body.src 1`] = `"'{' expected."`;
+
exports[`typescript fixtures/errorRecovery/object-assertion-not-allowed.src 1`] = `
Object {
"body": Array [
diff --git a/packages/shared-fixtures/fixtures/javascript/classes/class-with-no-body.src.js b/packages/shared-fixtures/fixtures/javascript/classes/class-with-no-body.src.js
new file mode 100644
index 000000000000..c389887ee5aa
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/javascript/classes/class-with-no-body.src.js
@@ -0,0 +1 @@
+class Foo
diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/interface-with-no-body.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/interface-with-no-body.src.ts
new file mode 100644
index 000000000000..3f943170b49e
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/interface-with-no-body.src.ts
@@ -0,0 +1 @@
+interface Foo
diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts
index c02a2eece24a..e5656e828934 100644
--- a/packages/typescript-estree/src/convert.ts
+++ b/packages/typescript-estree/src/convert.ts
@@ -1363,40 +1363,14 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression: {
const heritageClauses = node.heritageClauses || [];
-
let classNodeType = SyntaxKind[node.kind];
- let lastClassToken: any = heritageClauses.length
- ? heritageClauses[heritageClauses.length - 1]
- : node.name;
if (node.typeParameters && node.typeParameters.length) {
- const lastTypeParameter =
- node.typeParameters[node.typeParameters.length - 1];
-
- if (!lastClassToken || lastTypeParameter.pos > lastClassToken.pos) {
- lastClassToken = findNextToken(lastTypeParameter, ast, ast);
- }
result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
}
- if (node.modifiers && node.modifiers.length) {
- /**
- * We need check for modifiers, and use the last one, as there
- * could be multiple before the open brace
- */
- const lastModifier = node.modifiers![node.modifiers!.length - 1];
-
- if (!lastClassToken || lastModifier.pos > lastClassToken.pos) {
- lastClassToken = findNextToken(lastModifier, ast, ast);
- }
- } else if (!lastClassToken) {
- // no name
- lastClassToken = node.getFirstToken();
- }
-
- const openBrace = findNextToken(lastClassToken, ast, ast)!;
const superClass = heritageClauses.find(
clause => clause.token === SyntaxKind.ExtendsKeyword
);
@@ -1421,14 +1395,16 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
clause => clause.token === SyntaxKind.ImplementsKeyword
);
+ const classBodyRange = [node.members.pos - 1, node.end];
+
Object.assign(result, {
type: classNodeType,
id: convertChild(node.name),
body: {
type: AST_NODE_TYPES.ClassBody,
body: [],
- range: [openBrace.getStart(ast), node.end],
- loc: getLocFor(openBrace.getStart(ast), node.end, ast)
+ range: classBodyRange,
+ loc: getLocFor(classBodyRange[0], classBodyRange[1], ast)
},
superClass:
superClass && superClass.types[0]
@@ -2335,45 +2311,22 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
case SyntaxKind.InterfaceDeclaration: {
const interfaceHeritageClauses = node.heritageClauses || [];
- let interfaceLastClassToken = interfaceHeritageClauses.length
- ? interfaceHeritageClauses[interfaceHeritageClauses.length - 1]
- : node.name;
-
if (node.typeParameters && node.typeParameters.length) {
- const interfaceLastTypeParameter =
- node.typeParameters[node.typeParameters.length - 1];
-
- if (
- !interfaceLastClassToken ||
- interfaceLastTypeParameter.pos > interfaceLastClassToken.pos
- ) {
- interfaceLastClassToken = findNextToken(
- interfaceLastTypeParameter,
- ast,
- ast
- ) as any;
- }
result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
}
- const interfaceOpenBrace = findNextToken(
- interfaceLastClassToken,
- ast,
- ast
- )!;
-
- const interfaceBody = {
- type: AST_NODE_TYPES.TSInterfaceBody,
- body: node.members.map(member => convertChild(member)),
- range: [interfaceOpenBrace.getStart(ast), node.end],
- loc: getLocFor(interfaceOpenBrace.getStart(ast), node.end, ast)
- };
+ const interfaceBodyRange = [node.members.pos - 1, node.end];
Object.assign(result, {
type: AST_NODE_TYPES.TSInterfaceDeclaration,
- body: interfaceBody,
+ body: {
+ type: AST_NODE_TYPES.TSInterfaceBody,
+ body: node.members.map(member => convertChild(member)),
+ range: interfaceBodyRange,
+ loc: getLocFor(interfaceBodyRange[0], interfaceBodyRange[1], ast)
+ },
id: convertChild(node.name)
});
diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts
index fa780cfe8e97..240c4d1c9f71 100644
--- a/packages/typescript-estree/src/node-utils.ts
+++ b/packages/typescript-estree/src/node-utils.ts
@@ -359,13 +359,13 @@ export function getTSNodeAccessibility(
/**
* Finds the next token based on the previous one and its parent
* Had to copy this from TS instead of using TS's version because theirs doesn't pass the ast to getChildren
- * @param {ts.Node} previousToken The previous TSToken
+ * @param {ts.TextRange} previousToken The previous TSToken
* @param {ts.Node} parent The parent TSNode
* @param {ts.SourceFile} ast The TS AST
* @returns {ts.Node|undefined} the next TSToken
*/
export function findNextToken(
- previousToken: ts.Node,
+ previousToken: ts.TextRange,
parent: ts.Node,
ast: ts.SourceFile
): ts.Node | undefined {
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap
index eb2eb8f6f916..8d02532b8d7f 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap
@@ -30246,6 +30246,8 @@ Object {
}
`;
+exports[`javascript fixtures/classes/class-with-no-body.src 1`] = `"'{' expected."`;
+
exports[`javascript fixtures/classes/derived-class-assign-to-var.src 1`] = `
Object {
"body": Array [
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
index dfd7dbf783d0..e1186e5638a5 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
@@ -349,6 +349,15 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/class-with-constructor-with-space.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/class-with-no-body.src 1`] = `
+Object {
+ "column": 0,
+ "index": 10,
+ "lineNumber": 2,
+ "message": "'{' expected.",
+}
+`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/derived-class-assign-to-var.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/derived-class-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
@@ -2465,6 +2474,15 @@ Object {
}
`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/interface-with-no-body.src 1`] = `
+Object {
+ "column": 0,
+ "index": 14,
+ "lineNumber": 2,
+ "message": "'{' expected.",
+}
+`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/object-assertion-not-allowed.src 1`] = `
Object {
"column": 3,
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
index 6341ffcd7d74..c374e397a6e8 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
@@ -94859,6 +94859,8 @@ Object {
}
`;
+exports[`typescript fixtures/errorRecovery/interface-with-no-body.src 1`] = `"'{' expected."`;
+
exports[`typescript fixtures/errorRecovery/object-assertion-not-allowed.src 1`] = `
Object {
"body": Array [
From 91eedf20f3bd3940ba4576e8a8a48ad9fca01f15 Mon Sep 17 00:00:00 2001
From: Armano
Date: Wed, 23 Jan 2019 00:33:56 +0100
Subject: [PATCH 32/88] fix(typescript-estree): correct range of parameters
with comments (#128)
---
.../lib/__snapshots__/typescript.ts.snap | 2113 +++++++++++++++++
.../type-parameters-comments-heritage.src.ts | 4 +
packages/typescript-estree/src/convert.ts | 42 +-
.../semantic-diagnostics-enabled.ts.snap | 2 +
.../lib/__snapshots__/typescript.ts.snap | 1787 ++++++++++++++
5 files changed, 3915 insertions(+), 33 deletions(-)
create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/type-parameters-comments-heritage.src.ts
diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
index cd9460af3e32..39c74ab7586d 100644
--- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
@@ -66551,6 +66551,2119 @@ Object {
}
`;
+exports[`typescript fixtures/basics/type-parameters-comments-heritage.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 74,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 72,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 72,
+ 74,
+ ],
+ "type": "ClassBody",
+ },
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 6,
+ 9,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 74,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 74,
+ ],
+ "superClass": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 46,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 43,
+ "line": 1,
+ },
+ },
+ "name": "bar",
+ "range": Array [
+ 43,
+ 46,
+ ],
+ "type": "Identifier",
+ },
+ "superTypeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 71,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 60,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 59,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 59,
+ 60,
+ ],
+ "type": "TSTypeReference",
+ "typeName": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 60,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 59,
+ "line": 1,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 59,
+ 60,
+ ],
+ "type": "Identifier",
+ },
+ },
+ ],
+ "range": Array [
+ 47,
+ 71,
+ ],
+ "type": "TSTypeParameterInstantiation",
+ },
+ "type": "ClassDeclaration",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 34,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 23,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 23,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 22,
+ 23,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 22,
+ 23,
+ ],
+ "type": "TSTypeParameter",
+ },
+ ],
+ "range": Array [
+ 10,
+ 34,
+ ],
+ "type": "TSTypeParameterDeclaration",
+ },
+ },
+ Object {
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 89,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 87,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 162,
+ 164,
+ ],
+ "type": "ClassBody",
+ },
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "name": "foo2",
+ "range": Array [
+ 81,
+ 85,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 89,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 75,
+ 164,
+ ],
+ "superClass": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 61,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 58,
+ "line": 2,
+ },
+ },
+ "name": "bar",
+ "range": Array [
+ 133,
+ 136,
+ ],
+ "type": "Identifier",
+ },
+ "superTypeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 86,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 2,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 75,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 74,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 149,
+ 150,
+ ],
+ "type": "TSTypeReference",
+ "typeName": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 75,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 74,
+ "line": 2,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 149,
+ 150,
+ ],
+ "type": "Identifier",
+ },
+ },
+ ],
+ "range": Array [
+ 137,
+ 161,
+ ],
+ "type": "TSTypeParameterInstantiation",
+ },
+ "type": "ClassDeclaration",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 2,
+ },
+ },
+ "params": Array [
+ Object {
+ "default": Object {
+ "literal": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 37,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 112,
+ 113,
+ ],
+ "raw": "2",
+ "type": "Literal",
+ "value": 2,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 37,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 112,
+ 113,
+ ],
+ "type": "TSLiteralType",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 2,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 24,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 2,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 98,
+ 99,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 98,
+ 113,
+ ],
+ "type": "TSTypeParameter",
+ },
+ ],
+ "range": Array [
+ 86,
+ 124,
+ ],
+ "type": "TSTypeParameterDeclaration",
+ },
+ },
+ Object {
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 77,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 242,
+ 244,
+ ],
+ "type": "TSInterfaceBody",
+ },
+ "extends": Array [
+ Object {
+ "expression": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 51,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 3,
+ },
+ },
+ "name": "bar2",
+ "range": Array [
+ 212,
+ 216,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 76,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 212,
+ 241,
+ ],
+ "type": "TSInterfaceHeritage",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 76,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 52,
+ "line": 3,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 64,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 229,
+ 230,
+ ],
+ "type": "TSTypeReference",
+ "typeName": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 64,
+ "line": 3,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 229,
+ 230,
+ ],
+ "type": "Identifier",
+ },
+ },
+ ],
+ "range": Array [
+ 217,
+ 241,
+ ],
+ "type": "TSTypeParameterInstantiation",
+ },
+ },
+ ],
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 3,
+ },
+ },
+ "name": "bar",
+ "range": Array [
+ 175,
+ 178,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 165,
+ 244,
+ ],
+ "type": "TSInterfaceDeclaration",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 3,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 27,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 26,
+ "line": 3,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 27,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 26,
+ "line": 3,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 191,
+ 192,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 191,
+ 192,
+ ],
+ "type": "TSTypeParameter",
+ },
+ ],
+ "range": Array [
+ 179,
+ 203,
+ ],
+ "type": "TSTypeParameterDeclaration",
+ },
+ },
+ Object {
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 93,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 91,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 336,
+ 338,
+ ],
+ "type": "TSInterfaceBody",
+ },
+ "extends": Array [
+ Object {
+ "expression": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 4,
+ },
+ },
+ "name": "bar",
+ "range": Array [
+ 307,
+ 310,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 90,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 307,
+ 335,
+ ],
+ "type": "TSInterfaceHeritage",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 90,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 66,
+ "line": 4,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 78,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 323,
+ 324,
+ ],
+ "type": "TSTypeReference",
+ "typeName": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 78,
+ "line": 4,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 323,
+ 324,
+ ],
+ "type": "Identifier",
+ },
+ },
+ ],
+ "range": Array [
+ 311,
+ 335,
+ ],
+ "type": "TSTypeParameterInstantiation",
+ },
+ },
+ ],
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 4,
+ },
+ },
+ "name": "bar2",
+ "range": Array [
+ 255,
+ 259,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 93,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 245,
+ 338,
+ ],
+ "type": "TSInterfaceDeclaration",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 53,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 4,
+ },
+ },
+ "params": Array [
+ Object {
+ "default": Object {
+ "literal": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 41,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 286,
+ 287,
+ ],
+ "raw": "2",
+ "type": "Literal",
+ "value": 2,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 41,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 286,
+ 287,
+ ],
+ "type": "TSLiteralType",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 27,
+ "line": 4,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 27,
+ "line": 4,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 272,
+ 273,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 272,
+ 287,
+ ],
+ "type": "TSTypeParameter",
+ },
+ ],
+ "range": Array [
+ 260,
+ 298,
+ ],
+ "type": "TSTypeParameterDeclaration",
+ },
+ },
+ ],
+ "comments": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 12,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 12,
+ 21,
+ ],
+ "type": "Block",
+ "value": " aaa ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 33,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 24,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 24,
+ 33,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 58,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 49,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 49,
+ 58,
+ ],
+ "type": "Block",
+ "value": " aaa ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 70,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 61,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 61,
+ 70,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 22,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 88,
+ 97,
+ ],
+ "type": "Block",
+ "value": " aaa ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 34,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 25,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 100,
+ 109,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 48,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 39,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 114,
+ 123,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 73,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 64,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 139,
+ 148,
+ ],
+ "type": "Block",
+ "value": " aaa ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 85,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 76,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 151,
+ 160,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 25,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 16,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 181,
+ 190,
+ ],
+ "type": "Block",
+ "value": " aaa ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 37,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 28,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 193,
+ 202,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 63,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 54,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 219,
+ 228,
+ ],
+ "type": "Block",
+ "value": " aaa ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 75,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 66,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 231,
+ 240,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 26,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 262,
+ 271,
+ ],
+ "type": "Block",
+ "value": " aaa ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 29,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 274,
+ 283,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 52,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 43,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 288,
+ 297,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 77,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 68,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 313,
+ 322,
+ ],
+ "type": "Block",
+ "value": " aaa ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 89,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 80,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 325,
+ 334,
+ ],
+ "type": "Block",
+ "value": " bbb ",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 5,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 339,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "type": "Keyword",
+ "value": "class",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 6,
+ 9,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 10,
+ 11,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 23,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 22,
+ 23,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 34,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 33,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 33,
+ 34,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 35,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 35,
+ 42,
+ ],
+ "type": "Keyword",
+ "value": "extends",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 46,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 43,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 43,
+ 46,
+ ],
+ "type": "Identifier",
+ "value": "bar",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 48,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 47,
+ 48,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 60,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 59,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 59,
+ 60,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 71,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 70,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 70,
+ 71,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 73,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 72,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 72,
+ 73,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 74,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 73,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 73,
+ 74,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 75,
+ 80,
+ ],
+ "type": "Keyword",
+ "value": "class",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 81,
+ 85,
+ ],
+ "type": "Identifier",
+ "value": "foo2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 86,
+ 87,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 24,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 98,
+ 99,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 36,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 35,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 110,
+ 111,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 37,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 112,
+ 113,
+ ],
+ "type": "Numeric",
+ "value": "2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 48,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 123,
+ 124,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 57,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 50,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 125,
+ 132,
+ ],
+ "type": "Keyword",
+ "value": "extends",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 61,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 58,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 133,
+ 136,
+ ],
+ "type": "Identifier",
+ "value": "bar",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 63,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 137,
+ 138,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 75,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 74,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 149,
+ 150,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 86,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 85,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 160,
+ 161,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 88,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 87,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 162,
+ 163,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 89,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 88,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 163,
+ 164,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 165,
+ 174,
+ ],
+ "type": "Keyword",
+ "value": "interface",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 175,
+ 178,
+ ],
+ "type": "Identifier",
+ "value": "bar",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 179,
+ 180,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 27,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 26,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 191,
+ 192,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 37,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 202,
+ 203,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 46,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 39,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 204,
+ 211,
+ ],
+ "type": "Keyword",
+ "value": "extends",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 51,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 212,
+ 216,
+ ],
+ "type": "Identifier",
+ "value": "bar2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 53,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 52,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 217,
+ 218,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 64,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 229,
+ 230,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 76,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 75,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 240,
+ 241,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 78,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 77,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 242,
+ 243,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 78,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 243,
+ 244,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 245,
+ 254,
+ ],
+ "type": "Keyword",
+ "value": "interface",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 255,
+ 259,
+ ],
+ "type": "Identifier",
+ "value": "bar2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 260,
+ 261,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 27,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 272,
+ 273,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 40,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 39,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 284,
+ 285,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 41,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 286,
+ 287,
+ ],
+ "type": "Numeric",
+ "value": "2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 53,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 52,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 297,
+ 298,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 61,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 54,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 299,
+ 306,
+ ],
+ "type": "Keyword",
+ "value": "extends",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 307,
+ 310,
+ ],
+ "type": "Identifier",
+ "value": "bar",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 67,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 66,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 311,
+ 312,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 78,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 323,
+ 324,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 90,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 89,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 334,
+ 335,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 92,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 91,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 336,
+ 337,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 93,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 92,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 337,
+ 338,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`typescript fixtures/basics/type-reference-comments.src 1`] = `
Object {
"body": Array [
diff --git a/packages/shared-fixtures/fixtures/typescript/basics/type-parameters-comments-heritage.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/type-parameters-comments-heritage.src.ts
new file mode 100644
index 000000000000..986f4826089f
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/typescript/basics/type-parameters-comments-heritage.src.ts
@@ -0,0 +1,4 @@
+class foo < /* aaa */ A /* bbb */> extends bar < /* aaa */ A /* bbb */> {}
+class foo2 < /* aaa */ A /* bbb */ = 2 /* bbb */> extends bar < /* aaa */ A /* bbb */> {}
+interface bar < /* aaa */ A /* bbb */> extends bar2 < /* aaa */ A /* bbb */> {}
+interface bar2 < /* aaa */ A /* bbb */ = 2 /* bbb */> extends bar < /* aaa */ A /* bbb */> {}
diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts
index e5656e828934..64120d6a8d85 100644
--- a/packages/typescript-estree/src/convert.ts
+++ b/packages/typescript-estree/src/convert.ts
@@ -211,61 +211,37 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
}
/**
- * Converts a ts.Node's typeArguments ts.NodeArray to a flow-like typeParameters node
+ * Converts a ts.Node's typeArguments to TSTypeParameterInstantiation node
* @param {ts.NodeArray} typeArguments ts.Node typeArguments
* @returns {ESTreeNode} TypeParameterInstantiation node
*/
function convertTypeArgumentsToTypeParameters(
typeArguments: ts.NodeArray
): ESTreeNode {
- /**
- * Even if typeArguments is an empty array, TypeScript sets a `pos` and `end`
- * property on the array object so we can safely read the values here
- */
- const start = typeArguments.pos - 1;
- let end = typeArguments.end + 1;
- if (typeArguments && typeArguments.length) {
- const firstTypeArgument = typeArguments[0];
- const typeArgumentsParent = firstTypeArgument.parent;
- /**
- * In the case of the parent being a CallExpression or a TypeReference we have to use
- * slightly different logic to calculate the correct end position
- */
- if (
- typeArgumentsParent &&
- (typeArgumentsParent.kind === SyntaxKind.CallExpression ||
- typeArgumentsParent.kind === SyntaxKind.TypeReference)
- ) {
- const lastTypeArgument = typeArguments[typeArguments.length - 1];
- const greaterThanToken = findNextToken(lastTypeArgument, ast, ast);
- end = greaterThanToken!.end;
- }
- }
+ const greaterThanToken = findNextToken(typeArguments, ast, ast)!;
+
return {
type: AST_NODE_TYPES.TSTypeParameterInstantiation,
- range: [start, end],
- loc: getLocFor(start, end, ast),
+ range: [typeArguments.pos - 1, greaterThanToken.end],
+ loc: getLocFor(typeArguments.pos - 1, greaterThanToken.end, ast),
params: typeArguments.map(typeArgument => convertChildType(typeArgument))
};
}
/**
- * Converts a ts.Node's typeParameters ts.ts.NodeArray to a flow-like TypeParameterDeclaration node
+ * Converts a ts.Node's typeParameters to TSTypeParameterDeclaration node
* @param {ts.NodeArray} typeParameters ts.Node typeParameters
* @returns {ESTreeNode} TypeParameterDeclaration node
*/
function convertTSTypeParametersToTypeParametersDeclaration(
typeParameters: ts.NodeArray
): ESTreeNode {
- const firstTypeParameter = typeParameters[0];
- const lastTypeParameter = typeParameters[typeParameters.length - 1];
-
- const greaterThanToken = findNextToken(lastTypeParameter, ast, ast);
+ const greaterThanToken = findNextToken(typeParameters, ast, ast)!;
return {
type: AST_NODE_TYPES.TSTypeParameterDeclaration,
- range: [firstTypeParameter.pos - 1, greaterThanToken!.end],
- loc: getLocFor(firstTypeParameter.pos - 1, greaterThanToken!.end, ast),
+ range: [typeParameters.pos - 1, greaterThanToken.end],
+ loc: getLocFor(typeParameters.pos - 1, greaterThanToken.end, ast),
params: typeParameters.map(typeParameter =>
convertChildType(typeParameter)
)
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
index e1186e5638a5..768b79a8fd31 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
@@ -2129,6 +2129,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/type-parameters-comments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/type-parameters-comments-heritage.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/type-reference-comments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/typed-keyword-bigint.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
index c374e397a6e8..90ebe3e137e0 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
@@ -66263,6 +66263,1793 @@ Object {
}
`;
+exports[`typescript fixtures/basics/type-parameters-comments-heritage.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 74,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 72,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 72,
+ 74,
+ ],
+ "type": "ClassBody",
+ },
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 6,
+ 9,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 74,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 74,
+ ],
+ "superClass": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 46,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 43,
+ "line": 1,
+ },
+ },
+ "name": "bar",
+ "range": Array [
+ 43,
+ 46,
+ ],
+ "type": "Identifier",
+ },
+ "superTypeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 71,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 60,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 59,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 59,
+ 60,
+ ],
+ "type": "TSTypeReference",
+ "typeName": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 60,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 59,
+ "line": 1,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 59,
+ 60,
+ ],
+ "type": "Identifier",
+ },
+ },
+ ],
+ "range": Array [
+ 47,
+ 71,
+ ],
+ "type": "TSTypeParameterInstantiation",
+ },
+ "type": "ClassDeclaration",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 34,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 23,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 23,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 22,
+ 23,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 22,
+ 23,
+ ],
+ "type": "TSTypeParameter",
+ },
+ ],
+ "range": Array [
+ 10,
+ 34,
+ ],
+ "type": "TSTypeParameterDeclaration",
+ },
+ },
+ Object {
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 89,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 87,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 162,
+ 164,
+ ],
+ "type": "ClassBody",
+ },
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "name": "foo2",
+ "range": Array [
+ 81,
+ 85,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 89,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 75,
+ 164,
+ ],
+ "superClass": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 61,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 58,
+ "line": 2,
+ },
+ },
+ "name": "bar",
+ "range": Array [
+ 133,
+ 136,
+ ],
+ "type": "Identifier",
+ },
+ "superTypeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 86,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 2,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 75,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 74,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 149,
+ 150,
+ ],
+ "type": "TSTypeReference",
+ "typeName": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 75,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 74,
+ "line": 2,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 149,
+ 150,
+ ],
+ "type": "Identifier",
+ },
+ },
+ ],
+ "range": Array [
+ 137,
+ 161,
+ ],
+ "type": "TSTypeParameterInstantiation",
+ },
+ "type": "ClassDeclaration",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 2,
+ },
+ },
+ "params": Array [
+ Object {
+ "default": Object {
+ "literal": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 37,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 112,
+ 113,
+ ],
+ "raw": "2",
+ "type": "Literal",
+ "value": 2,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 37,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 112,
+ 113,
+ ],
+ "type": "TSLiteralType",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 2,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 24,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 2,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 98,
+ 99,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 98,
+ 113,
+ ],
+ "type": "TSTypeParameter",
+ },
+ ],
+ "range": Array [
+ 86,
+ 124,
+ ],
+ "type": "TSTypeParameterDeclaration",
+ },
+ },
+ Object {
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 77,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 242,
+ 244,
+ ],
+ "type": "TSInterfaceBody",
+ },
+ "extends": Array [
+ Object {
+ "expression": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 51,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 3,
+ },
+ },
+ "name": "bar2",
+ "range": Array [
+ 212,
+ 216,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 76,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 212,
+ 241,
+ ],
+ "type": "TSInterfaceHeritage",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 76,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 52,
+ "line": 3,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 64,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 229,
+ 230,
+ ],
+ "type": "TSTypeReference",
+ "typeName": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 64,
+ "line": 3,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 229,
+ 230,
+ ],
+ "type": "Identifier",
+ },
+ },
+ ],
+ "range": Array [
+ 217,
+ 241,
+ ],
+ "type": "TSTypeParameterInstantiation",
+ },
+ },
+ ],
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 3,
+ },
+ },
+ "name": "bar",
+ "range": Array [
+ 175,
+ 178,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 165,
+ 244,
+ ],
+ "type": "TSInterfaceDeclaration",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 3,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 27,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 26,
+ "line": 3,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 27,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 26,
+ "line": 3,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 191,
+ 192,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 191,
+ 192,
+ ],
+ "type": "TSTypeParameter",
+ },
+ ],
+ "range": Array [
+ 179,
+ 203,
+ ],
+ "type": "TSTypeParameterDeclaration",
+ },
+ },
+ Object {
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 93,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 91,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 336,
+ 338,
+ ],
+ "type": "TSInterfaceBody",
+ },
+ "extends": Array [
+ Object {
+ "expression": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 4,
+ },
+ },
+ "name": "bar",
+ "range": Array [
+ 307,
+ 310,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 90,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 307,
+ 335,
+ ],
+ "type": "TSInterfaceHeritage",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 90,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 66,
+ "line": 4,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 78,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 323,
+ 324,
+ ],
+ "type": "TSTypeReference",
+ "typeName": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 78,
+ "line": 4,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 323,
+ 324,
+ ],
+ "type": "Identifier",
+ },
+ },
+ ],
+ "range": Array [
+ 311,
+ 335,
+ ],
+ "type": "TSTypeParameterInstantiation",
+ },
+ },
+ ],
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 4,
+ },
+ },
+ "name": "bar2",
+ "range": Array [
+ 255,
+ 259,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 93,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 245,
+ 338,
+ ],
+ "type": "TSInterfaceDeclaration",
+ "typeParameters": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 53,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 4,
+ },
+ },
+ "params": Array [
+ Object {
+ "default": Object {
+ "literal": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 41,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 286,
+ 287,
+ ],
+ "raw": "2",
+ "type": "Literal",
+ "value": 2,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 41,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 286,
+ 287,
+ ],
+ "type": "TSLiteralType",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 27,
+ "line": 4,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 27,
+ "line": 4,
+ },
+ },
+ "name": "A",
+ "range": Array [
+ 272,
+ 273,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 272,
+ 287,
+ ],
+ "type": "TSTypeParameter",
+ },
+ ],
+ "range": Array [
+ 260,
+ 298,
+ ],
+ "type": "TSTypeParameterDeclaration",
+ },
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 5,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 339,
+ ],
+ "sourceType": "script",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "type": "Keyword",
+ "value": "class",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 6,
+ 9,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 10,
+ 11,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 23,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 22,
+ 23,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 34,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 33,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 33,
+ 34,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 35,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 35,
+ 42,
+ ],
+ "type": "Keyword",
+ "value": "extends",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 46,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 43,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 43,
+ 46,
+ ],
+ "type": "Identifier",
+ "value": "bar",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 48,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 47,
+ 48,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 60,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 59,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 59,
+ 60,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 71,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 70,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 70,
+ 71,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 73,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 72,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 72,
+ 73,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 74,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 73,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 73,
+ 74,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 75,
+ 80,
+ ],
+ "type": "Keyword",
+ "value": "class",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 81,
+ 85,
+ ],
+ "type": "Identifier",
+ "value": "foo2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 86,
+ 87,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 24,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 98,
+ 99,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 36,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 35,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 110,
+ 111,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 37,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 112,
+ 113,
+ ],
+ "type": "Numeric",
+ "value": "2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 48,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 123,
+ 124,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 57,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 50,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 125,
+ 132,
+ ],
+ "type": "Keyword",
+ "value": "extends",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 61,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 58,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 133,
+ 136,
+ ],
+ "type": "Identifier",
+ "value": "bar",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 63,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 137,
+ 138,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 75,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 74,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 149,
+ 150,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 86,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 85,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 160,
+ 161,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 88,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 87,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 162,
+ 163,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 89,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 88,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 163,
+ 164,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 165,
+ 174,
+ ],
+ "type": "Keyword",
+ "value": "interface",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 175,
+ 178,
+ ],
+ "type": "Identifier",
+ "value": "bar",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 179,
+ 180,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 27,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 26,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 191,
+ 192,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 37,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 202,
+ 203,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 46,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 39,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 204,
+ 211,
+ ],
+ "type": "Keyword",
+ "value": "extends",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 51,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 47,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 212,
+ 216,
+ ],
+ "type": "Identifier",
+ "value": "bar2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 53,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 52,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 217,
+ 218,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 64,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 229,
+ 230,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 76,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 75,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 240,
+ 241,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 78,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 77,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 242,
+ 243,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 78,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 243,
+ 244,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 245,
+ 254,
+ ],
+ "type": "Keyword",
+ "value": "interface",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 255,
+ 259,
+ ],
+ "type": "Identifier",
+ "value": "bar2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 260,
+ 261,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 27,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 272,
+ 273,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 40,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 39,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 284,
+ 285,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 41,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 286,
+ 287,
+ ],
+ "type": "Numeric",
+ "value": "2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 53,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 52,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 297,
+ 298,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 61,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 54,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 299,
+ 306,
+ ],
+ "type": "Keyword",
+ "value": "extends",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 65,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 62,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 307,
+ 310,
+ ],
+ "type": "Identifier",
+ "value": "bar",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 67,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 66,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 311,
+ 312,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 79,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 78,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 323,
+ 324,
+ ],
+ "type": "Identifier",
+ "value": "A",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 90,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 89,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 334,
+ 335,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 92,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 91,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 336,
+ 337,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 93,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 92,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 337,
+ 338,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`typescript fixtures/basics/type-reference-comments.src 1`] = `
Object {
"body": Array [
From 9f501a1dce558457ca40b6e9f6a851709b296ed3 Mon Sep 17 00:00:00 2001
From: Armano
Date: Wed, 23 Jan 2019 00:49:23 +0100
Subject: [PATCH 33/88] feat(eslint-plugin): add option to
no-object-literal-type-assertion rule (#87)
---
.../rules/no-object-literal-type-assertion.md | 6 ++-
.../rules/no-object-literal-type-assertion.js | 31 ++++++++++++++-
.../rules/no-object-literal-type-assertion.js | 38 ++++++++++++++++++-
3 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/packages/eslint-plugin/docs/rules/no-object-literal-type-assertion.md b/packages/eslint-plugin/docs/rules/no-object-literal-type-assertion.md
index fe25f8f64107..b81ae0d87b69 100644
--- a/packages/eslint-plugin/docs/rules/no-object-literal-type-assertion.md
+++ b/packages/eslint-plugin/docs/rules/no-object-literal-type-assertion.md
@@ -20,9 +20,11 @@ const z = { ... } as unknown;
## Options
-```json
+```cjson
{
- "@typescript-eslint/no-object-literal-type-assertion": "error"
+ "@typescript-eslint/no-object-literal-type-assertion": ["error", {
+ allowAsParameter: false // Allow type assertion in call and new expression, default false
+ }]
}
```
diff --git a/packages/eslint-plugin/lib/rules/no-object-literal-type-assertion.js b/packages/eslint-plugin/lib/rules/no-object-literal-type-assertion.js
index f98a28a38f0c..11258a99315f 100644
--- a/packages/eslint-plugin/lib/rules/no-object-literal-type-assertion.js
+++ b/packages/eslint-plugin/lib/rules/no-object-literal-type-assertion.js
@@ -10,6 +10,12 @@ const util = require('../util');
// Rule Definition
//------------------------------------------------------------------------------
+const defaultOptions = [
+ {
+ allowAsParameter: false
+ }
+];
+
module.exports = {
meta: {
type: 'problem',
@@ -25,9 +31,24 @@ module.exports = {
unexpectedTypeAssertion:
'Type assertion on object literals is forbidden, use a type annotation instead.'
},
- schema: []
+ schema: [
+ {
+ type: 'object',
+ additionalProperties: false,
+ properties: {
+ allowAsParameter: {
+ type: 'boolean'
+ }
+ }
+ }
+ ]
},
create(context) {
+ const { allowAsParameter } = util.applyDefault(
+ defaultOptions,
+ context.options
+ )[0];
+
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
@@ -52,6 +73,14 @@ module.exports = {
return {
'TSTypeAssertion, TSAsExpression'(node) {
+ if (
+ allowAsParameter &&
+ (node.parent.type === 'NewExpression' ||
+ node.parent.type === 'CallExpression')
+ ) {
+ return;
+ }
+
if (
checkType(node.typeAnnotation) &&
node.expression.type === 'ObjectExpression'
diff --git a/packages/eslint-plugin/tests/lib/rules/no-object-literal-type-assertion.js b/packages/eslint-plugin/tests/lib/rules/no-object-literal-type-assertion.js
index 2a037390e0b5..aa19b09e8601 100644
--- a/packages/eslint-plugin/tests/lib/rules/no-object-literal-type-assertion.js
+++ b/packages/eslint-plugin/tests/lib/rules/no-object-literal-type-assertion.js
@@ -39,7 +39,23 @@ ruleTester.run('no-object-literal-type-assertion', rule, {
`const foo = {};`,
// Allow cast to 'unknown'
`const foo = {} as unknown;`,
- `const foo = {};`
+ `const foo = {};`,
+ {
+ code: `print({ bar: 5 } as Foo)`,
+ options: [
+ {
+ allowAsParameter: true
+ }
+ ]
+ },
+ {
+ code: `new print({ bar: 5 } as Foo)`,
+ options: [
+ {
+ allowAsParameter: true
+ }
+ ]
+ }
],
invalid: [
{
@@ -71,6 +87,26 @@ ruleTester.run('no-object-literal-type-assertion', rule, {
column: 11
}
]
+ },
+ {
+ code: `print({ bar: 5 } as Foo)`,
+ errors: [
+ {
+ messageId: 'unexpectedTypeAssertion',
+ line: 1,
+ column: 7
+ }
+ ]
+ },
+ {
+ code: `new print({ bar: 5 } as Foo)`,
+ errors: [
+ {
+ messageId: 'unexpectedTypeAssertion',
+ line: 1,
+ column: 11
+ }
+ ]
}
]
});
From da7e91e1b3e6f90d51bf3442e9c2771af1d61118 Mon Sep 17 00:00:00 2001
From: James Henry
Date: Tue, 22 Jan 2019 19:01:11 -0500
Subject: [PATCH 34/88] chore: publish v1.1.0
---
CHANGELOG.md | 14 ++++++++++++++
lerna.json | 2 +-
packages/eslint-plugin-tslint/CHANGELOG.md | 4 ++++
packages/eslint-plugin-tslint/package.json | 4 ++--
packages/eslint-plugin/CHANGELOG.md | 12 ++++++++++++
packages/eslint-plugin/package.json | 4 ++--
packages/parser/CHANGELOG.md | 7 +++++++
packages/parser/package.json | 6 +++---
packages/shared-fixtures/CHANGELOG.md | 11 +++++++++++
packages/shared-fixtures/package.json | 2 +-
packages/typescript-estree/CHANGELOG.md | 7 +++++++
packages/typescript-estree/package.json | 4 ++--
12 files changed, 66 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c87104215644..6fbb5db67f5c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,20 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
+
+### Bug Fixes
+
+- **eslint-plugin:** don’t mark `declare class` as unused ([#110](https://github.com/typescript-eslint/typescript-eslint/issues/110)) ([5841cd2](https://github.com/typescript-eslint/typescript-eslint/commit/5841cd2)), closes [#106](https://github.com/typescript-eslint/typescript-eslint/issues/106)
+- **eslint-plugin:** improve detection of used vars in heritage ([#102](https://github.com/typescript-eslint/typescript-eslint/issues/102)) ([193b434](https://github.com/typescript-eslint/typescript-eslint/commit/193b434))
+- **typescript-estree:** correct range of parameters with comments ([#128](https://github.com/typescript-eslint/typescript-eslint/issues/128)) ([91eedf2](https://github.com/typescript-eslint/typescript-eslint/commit/91eedf2))
+- **typescript-estree:** fix range of assignment in parameter ([#115](https://github.com/typescript-eslint/typescript-eslint/issues/115)) ([4e781f1](https://github.com/typescript-eslint/typescript-eslint/commit/4e781f1))
+
+### Features
+
+- **eslint-plugin:** add new rule restrict-plus-operands ([#70](https://github.com/typescript-eslint/typescript-eslint/issues/70)) ([c541ede](https://github.com/typescript-eslint/typescript-eslint/commit/c541ede))
+- **eslint-plugin:** add option to no-object-literal-type-assertion rule ([#87](https://github.com/typescript-eslint/typescript-eslint/issues/87)) ([9f501a1](https://github.com/typescript-eslint/typescript-eslint/commit/9f501a1))
+
# [1.0.0](https://github.com/typescript-eslint/typescript-eslint/compare/v0.2.1...v1.0.0) (2019-01-20)
### Bug Fixes
diff --git a/lerna.json b/lerna.json
index c416cf72769b..844b711bb0fe 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
{
- "version": "1.0.0",
+ "version": "1.1.0",
"npmClient": "yarn",
"useWorkspaces": true,
"stream": true
diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md
index a95c7b88cb36..6b4306f26855 100644
--- a/packages/eslint-plugin-tslint/CHANGELOG.md
+++ b/packages/eslint-plugin-tslint/CHANGELOG.md
@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
+
+**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
+
# [1.0.0](https://github.com/typescript-eslint/typescript-eslint/compare/v0.2.1...v1.0.0) (2019-01-20)
**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json
index 9c0668115ecc..fbe9ea5521e0 100644
--- a/packages/eslint-plugin-tslint/package.json
+++ b/packages/eslint-plugin-tslint/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin-tslint",
- "version": "1.0.0",
+ "version": "1.1.0",
"main": "dist/index.js",
"typings": "src/index.ts",
"description": "TSLint wrapper plugin for ESLint",
@@ -33,6 +33,6 @@
"devDependencies": {
"@types/eslint": "^4.16.3",
"@types/lodash.memoize": "^4.1.4",
- "@typescript-eslint/parser": "1.0.0"
+ "@typescript-eslint/parser": "1.1.0"
}
}
diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md
index 188e6b07bec3..39a512dab49e 100644
--- a/packages/eslint-plugin/CHANGELOG.md
+++ b/packages/eslint-plugin/CHANGELOG.md
@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
+
+### Bug Fixes
+
+- **eslint-plugin:** don’t mark `declare class` as unused ([#110](https://github.com/typescript-eslint/typescript-eslint/issues/110)) ([5841cd2](https://github.com/typescript-eslint/typescript-eslint/commit/5841cd2)), closes [#106](https://github.com/typescript-eslint/typescript-eslint/issues/106)
+- **eslint-plugin:** improve detection of used vars in heritage ([#102](https://github.com/typescript-eslint/typescript-eslint/issues/102)) ([193b434](https://github.com/typescript-eslint/typescript-eslint/commit/193b434))
+
+### Features
+
+- **eslint-plugin:** add new rule restrict-plus-operands ([#70](https://github.com/typescript-eslint/typescript-eslint/issues/70)) ([c541ede](https://github.com/typescript-eslint/typescript-eslint/commit/c541ede))
+- **eslint-plugin:** add option to no-object-literal-type-assertion rule ([#87](https://github.com/typescript-eslint/typescript-eslint/issues/87)) ([9f501a1](https://github.com/typescript-eslint/typescript-eslint/commit/9f501a1))
+
# [1.0.0](https://github.com/typescript-eslint/typescript-eslint/compare/v0.2.1...v1.0.0) (2019-01-20)
### Bug Fixes
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index 34d125380e4c..7cd6f21b1ab3 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin",
- "version": "1.0.0",
+ "version": "1.1.0",
"description": "TypeScript plugin for ESLint",
"keywords": [
"eslint",
@@ -24,7 +24,7 @@
"recommended:update": "node tools/update-recommended.js"
},
"dependencies": {
- "@typescript-eslint/parser": "1.0.0",
+ "@typescript-eslint/parser": "1.1.0",
"requireindex": "^1.2.0"
},
"devDependencies": {
diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md
index 1e519885b94a..3c8b8d4e4efc 100644
--- a/packages/parser/CHANGELOG.md
+++ b/packages/parser/CHANGELOG.md
@@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
+
+### Bug Fixes
+
+- **typescript-estree:** correct range of parameters with comments ([#128](https://github.com/typescript-eslint/typescript-eslint/issues/128)) ([91eedf2](https://github.com/typescript-eslint/typescript-eslint/commit/91eedf2))
+- **typescript-estree:** fix range of assignment in parameter ([#115](https://github.com/typescript-eslint/typescript-eslint/issues/115)) ([4e781f1](https://github.com/typescript-eslint/typescript-eslint/commit/4e781f1))
+
# [1.0.0](https://github.com/typescript-eslint/typescript-eslint/compare/v0.2.1...v1.0.0) (2019-01-20)
### Features
diff --git a/packages/parser/package.json b/packages/parser/package.json
index be34576e324c..23fe47afce3f 100644
--- a/packages/parser/package.json
+++ b/packages/parser/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/parser",
- "version": "1.0.0",
+ "version": "1.1.0",
"description": "An ESLint custom parser which leverages TypeScript ESTree",
"main": "dist/parser.js",
"files": [
@@ -36,7 +36,7 @@
"typescript": "*"
},
"dependencies": {
- "@typescript-eslint/typescript-estree": "1.0.0",
+ "@typescript-eslint/typescript-estree": "1.1.0",
"eslint-scope": "^4.0.0",
"eslint-visitor-keys": "^1.0.0"
},
@@ -44,6 +44,6 @@
"@types/eslint": "^4.16.5",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/estree": "^0.0.39",
- "@typescript-eslint/shared-fixtures": "1.0.0"
+ "@typescript-eslint/shared-fixtures": "1.1.0"
}
}
diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md
index 2b7402f262e4..3114aaabc99c 100644
--- a/packages/shared-fixtures/CHANGELOG.md
+++ b/packages/shared-fixtures/CHANGELOG.md
@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
+
+
+### Bug Fixes
+
+* **typescript-estree:** correct range of parameters with comments ([#128](https://github.com/typescript-eslint/typescript-eslint/issues/128)) ([91eedf2](https://github.com/typescript-eslint/typescript-eslint/commit/91eedf2))
+
+
+
+
+
# [1.0.0](https://github.com/typescript-eslint/typescript-eslint/compare/v0.2.1...v1.0.0) (2019-01-20)
**Note:** Version bump only for package @typescript-eslint/shared-fixtures
diff --git a/packages/shared-fixtures/package.json b/packages/shared-fixtures/package.json
index 4478df0606e9..2424070165f4 100644
--- a/packages/shared-fixtures/package.json
+++ b/packages/shared-fixtures/package.json
@@ -1,5 +1,5 @@
{
"name": "@typescript-eslint/shared-fixtures",
- "version": "1.0.0",
+ "version": "1.1.0",
"private": true
}
diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md
index 39323d365fd7..be11f821f745 100644
--- a/packages/typescript-estree/CHANGELOG.md
+++ b/packages/typescript-estree/CHANGELOG.md
@@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
+
+### Bug Fixes
+
+- **typescript-estree:** correct range of parameters with comments ([#128](https://github.com/typescript-eslint/typescript-eslint/issues/128)) ([91eedf2](https://github.com/typescript-eslint/typescript-eslint/commit/91eedf2))
+- **typescript-estree:** fix range of assignment in parameter ([#115](https://github.com/typescript-eslint/typescript-eslint/issues/115)) ([4e781f1](https://github.com/typescript-eslint/typescript-eslint/commit/4e781f1))
+
# [1.0.0](https://github.com/typescript-eslint/typescript-eslint/compare/v0.2.1...v1.0.0) (2019-01-20)
### Features
diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json
index 10d0639be1f4..a8490f513a68 100644
--- a/packages/typescript-estree/package.json
+++ b/packages/typescript-estree/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/typescript-estree",
- "version": "1.0.0",
+ "version": "1.1.0",
"description": "A parser that converts TypeScript source code into an ESTree compatible form",
"main": "dist/parser.js",
"files": [
@@ -41,7 +41,7 @@
"typescript": "*"
},
"devDependencies": {
- "@typescript-eslint/shared-fixtures": "1.0.0",
+ "@typescript-eslint/shared-fixtures": "1.1.0",
"typescript": "~3.2.1"
}
}
From 7ed099706d1175bb92b9422a4c71f7e81420ddc2 Mon Sep 17 00:00:00 2001
From: Jed Fox
Date: Wed, 23 Jan 2019 07:51:47 -0500
Subject: [PATCH 35/88] docs(eslint-plugin): update rule names in the roadmap
(#108)
---
packages/eslint-plugin/ROADMAP.md | 144 +++++++++++++++---------------
1 file changed, 72 insertions(+), 72 deletions(-)
diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md
index eb0cf5e33ec4..1fce16992a9c 100644
--- a/packages/eslint-plugin/ROADMAP.md
+++ b/packages/eslint-plugin/ROADMAP.md
@@ -10,30 +10,30 @@
### TypeScript-specific
-| TSLint rule | | ESLint rule |
-| --------------------------------- | :-: | -------------------------------------------- |
-| [`adjacent-overload-signatures`] | ✅ | [`typescript/adjacent-overload-signatures`] |
-| [`ban-types`] | ✅ | [`typescript/ban-types`] |
-| [`member-access`] | ✅ | [`typescript/explicit-member-accessibility`] |
-| [`member-ordering`] | ✅ | [`typescript/member-ordering`] |
-| [`no-any`] | ✅ | [`typescript/no-explicit-any`] |
-| [`no-empty-interface`] | ✅ | [`typescript/no-empty-interface`] |
-| [`no-import-side-effect`] | 🔌 | [`import/no-unassigned-import`] |
-| [`no-inferrable-types`] | ✅ | [`typescript/no-inferrable-types`] |
-| [`no-internal-module`] | ✅ | [`typescript/prefer-namespace-keyword`] |
-| [`no-magic-numbers`] | 🌟 | [`no-magic-numbers`][no-magic-numbers] |
-| [`no-namespace`] | ✅ | [`typescript/no-namespace`] |
-| [`no-non-null-assertion`] | ✅ | [`typescript/no-non-null-assertion`] |
-| [`no-parameter-reassignment`] | ✅ | [`no-param-reassign`][no-param-reassign] |
-| [`no-reference`] | ✅ | [`typescript/no-triple-slash-reference`] |
-| [`no-unnecessary-type-assertion`] | 🛑 | N/A |
-| [`no-var-requires`] | ✅ | [`typescript/no-var-requires`] |
-| [`only-arrow-functions`] | 🔌 | [`prefer-arrow/prefer-arrow-functions`] |
-| [`prefer-for-of`] | 🛑 | N/A |
-| [`promise-function-async`] | 🛑 | N/A ([relevant plugin][plugin:promise]) |
-| [`typedef`] | 🛑 | N/A |
-| [`typedef-whitespace`] | ✅ | [`typescript/type-annotation-spacing`] |
-| [`unified-signatures`] | 🛑 | N/A |
+| TSLint rule | | ESLint rule |
+| --------------------------------- | :-: | ---------------------------------------------------- |
+| [`adjacent-overload-signatures`] | ✅ | [`@typescript-eslint/adjacent-overload-signatures`] |
+| [`ban-types`] | ✅ | [`@typescript-eslint/ban-types`] |
+| [`member-access`] | ✅ | [`@typescript-eslint/explicit-member-accessibility`] |
+| [`member-ordering`] | ✅ | [`@typescript-eslint/member-ordering`] |
+| [`no-any`] | ✅ | [`@typescript-eslint/no-explicit-any`] |
+| [`no-empty-interface`] | ✅ | [`@typescript-eslint/no-empty-interface`] |
+| [`no-import-side-effect`] | 🔌 | [`import/no-unassigned-import`] |
+| [`no-inferrable-types`] | ✅ | [`@typescript-eslint/no-inferrable-types`] |
+| [`no-internal-module`] | ✅ | [`@typescript-eslint/prefer-namespace-keyword`] |
+| [`no-magic-numbers`] | 🌟 | [`no-magic-numbers`][no-magic-numbers] |
+| [`no-namespace`] | ✅ | [`@typescript-eslint/no-namespace`] |
+| [`no-non-null-assertion`] | ✅ | [`@typescript-eslint/no-non-null-assertion`] |
+| [`no-parameter-reassignment`] | ✅ | [`no-param-reassign`][no-param-reassign] |
+| [`no-reference`] | ✅ | [`@typescript-eslint/no-triple-slash-reference`] |
+| [`no-unnecessary-type-assertion`] | 🛑 | N/A |
+| [`no-var-requires`] | ✅ | [`@typescript-eslint/no-var-requires`] |
+| [`only-arrow-functions`] | 🔌 | [`prefer-arrow/prefer-arrow-functions`] |
+| [`prefer-for-of`] | 🛑 | N/A |
+| [`promise-function-async`] | 🛑 | N/A ([relevant plugin][plugin:promise]) |
+| [`typedef`] | 🛑 | N/A |
+| [`typedef-whitespace`] | ✅ | [`@typescript-eslint/type-annotation-spacing`] |
+| [`unified-signatures`] | 🛑 | N/A |
### Functionality
@@ -64,9 +64,9 @@
| [`no-inferred-empty-object-type`] | 🛑 | N/A |
| [`no-invalid-template-strings`] | 🌟 | [`no-template-curly-in-string`][no-template-curly-in-string] |
| [`no-invalid-this`] | 🌟 | [`no-invalid-this`][no-invalid-this] |
-| [`no-misused-new`] | ✅ | [`typescript/no-misused-new`] |
+| [`no-misused-new`] | ✅ | [`@typescript-eslint/no-misused-new`] |
| [`no-null-keyword`] | 🔌 | [`no-null/no-null`] (doesn’t handle `null` type) |
-| [`no-object-literal-type-assertion`] | ✅ | [`typescript/no-object-literal-type-assertion`] |
+| [`no-object-literal-type-assertion`] | ✅ | [`@typescript-eslint/no-object-literal-type-assertion`] |
| [`no-return-await`] | 🌟 | [`no-return-await`][no-return-await] |
| [`no-shadowed-variable`] | 🌟 | [`no-shadow`][no-shadow] |
| [`no-sparse-arrays`] | 🌟 | [`no-sparse-arrays`][no-sparse-arrays] |
@@ -74,14 +74,14 @@
| [`no-string-throw`] | 🌟 | [`no-throw-literal`][no-throw-literal] |
| [`no-submodule-imports`] | 🌓 | [`import/no-internal-modules`] (slightly different) |
| [`no-switch-case-fall-through`] | 🌟 | [`no-fallthrough`][no-fallthrough] |
-| [`no-this-assignment`] | ✅ | [`typescript/no-this-alias`] |
+| [`no-this-assignment`] | ✅ | [`@typescript-eslint/no-this-alias`] |
| [`no-unbound-method`] | 🛑 | N/A |
-| [`no-unnecessary-class`] | ✅ | [`typescript/no-extraneous-class`] |
+| [`no-unnecessary-class`] | ✅ | [`@typescript-eslint/no-extraneous-class`] |
| [`no-unsafe-any`] | 🛑 | N/A |
| [`no-unsafe-finally`] | 🌟 | [`no-unsafe-finally`][no-unsafe-finally] |
| [`no-unused-expression`] | 🌟 | [`no-unused-expression`][no-unused-expressions] |
| [`no-unused-variable`] | 🌓 | [`no-unused-vars`][no-unused-vars] [2] |
-| [`no-use-before-declare`] | ✅ | [`typescript/no-use-before-define`] |
+| [`no-use-before-declare`] | ✅ | [`@typescript-eslint/no-use-before-define`] |
| [`no-var-keyword`] | 🌟 | [`no-var`][no-var] |
| [`no-void-expression`] | 🌟 | [`no-void`][no-void] |
| [`prefer-conditional-expression`] | 🛑 | N/A |
@@ -97,7 +97,7 @@
| [`use-isnan`] | 🌟 | [`use-isnan`][use-isnan] |
[1] The ESLint rule also supports silencing with an extra set of parens (`if ((foo = bar)) {}`)
-[2] Missing private class member support. [`typescript/no-unused-vars`] adds support for some TS-specific features.
+[2] Missing private class member support. [`@typescript-eslint/no-unused-vars`] adds support for some TS-specific features.
### Maintainability
@@ -106,7 +106,7 @@
| [`cyclomatic-complexity`] | 🌟 | [`complexity`][complexity] |
| [`deprecation`] | 🌓 | [`import/no-deprecated`] [1] |
| [`eofline`] | 🌟 | [`eol-last`][eol-last] |
-| [`indent`] | ✅ | [`typescript/indent`] or [Prettier] |
+| [`indent`] | ✅ | [`@typescript-eslint/indent`] or [Prettier] |
| [`linebreak-style`] | 🌟 | [`linebreak-style`][linebreak-style] or [Prettier] |
| [`max-classes-per-file`] | 🌟 | [`max-classes-per-file`][max-classes-per-file] |
| [`max-file-line-count`] | 🌟 | [`max-lines`][max-lines] |
@@ -128,30 +128,30 @@
| TSLint rule | | ESLint rule |
| ----------------------------------- | :-: | ----------------------------------------------------------------------------------- |
| [`align`] | 🛑 | N/A |
-| [`array-type`] | ✅ | [`typescript/array-type`] |
+| [`array-type`] | ✅ | [`@typescript-eslint/array-type`] |
| [`arrow-parens`] | 🌟 | [`arrow-parens`][arrow-parens] |
| [`arrow-return-shorthand`] | 🌟 | [`arrow-body-style`][arrow-body-style] |
| [`binary-expression-operand-order`] | 🌟 | [`yoda`][yoda] |
| [`callable-types`] | 🛑 | N/A |
-| [`class-name`] | ✅ | [`typescript/class-name-casing`] |
+| [`class-name`] | ✅ | [`@typescript-eslint/class-name-casing`] |
| [`comment-format`] | 🌟 | [`capitalized-comments`][capitalized-comments] & [`spaced-comment`][spaced-comment] |
| [`completed-docs`] | 🔌 | [`eslint-plugin-jsdoc`][plugin:jsdoc] |
| [`encoding`] | 🛑 | N/A |
| [`file-header`] | 🔌 | [`eslint-plugin-header`][plugin:header] or [`-file-header`][plugin:file-header] |
| [`file-name-casing`] | 🔌 | [`unicorn/filename-case`] |
| [`import-spacing`] | 🔌 | Use [Prettier] |
-| [`interface-name`] | ✅ | [`typescript/interface-name-prefix`] |
-| [`interface-over-type-literal`] | ✅ | [`typescript/prefer-interface`] |
+| [`interface-name`] | ✅ | [`@typescript-eslint/interface-name-prefix`] |
+| [`interface-over-type-literal`] | ✅ | [`@typescript-eslint/prefer-interface`] |
| [`jsdoc-format`] | 🌓 | [`valid-jsdoc`][valid-jsdoc] or [`eslint-plugin-jsdoc`][plugin:jsdoc] |
| [`match-default-export-name`] | 🛑 | N/A |
| [`newline-before-return`] | 🌟 | [`padding-line-between-statements`][padding-line-between-statements] [1] |
| [`newline-per-chained-call`] | 🌟 | [`newline-per-chained-call`][newline-per-chained-call] |
| [`new-parens`] | 🌟 | [`new-parens`][new-parens] |
-| [`no-angle-bracket-type-assertion`] | ✅ | [`typescript/no-angle-bracket-type-assertion`] |
+| [`no-angle-bracket-type-assertion`] | ✅ | [`@typescript-eslint/no-angle-bracket-type-assertion`] |
| [`no-boolean-literal-compare`] | 🛑 | N/A |
| [`no-consecutive-blank-lines`] | 🌟 | [`no-multiple-empty-lines`][no-multiple-empty-lines] |
| [`no-irregular-whitespace`] | 🌟 | [`no-irregular-whitespace`][no-irregular-whitespace] with `skipStrings: false` |
-| [`no-parameter-properties`] | ✅ | [`typescript/no-parameter-properties`] |
+| [`no-parameter-properties`] | ✅ | [`@typescript-eslint/no-parameter-properties`] |
| [`no-redundant-jsdoc`] | 🛑 | N/A ([open issue](https://github.com/gajus/eslint-plugin-jsdoc/issues/134)) |
| [`no-reference-import`] | 🛑 | N/A |
| [`no-trailing-whitespace`] | 🌟 | [`no-trailing-spaces`][no-trailing-spaces] |
@@ -175,12 +175,12 @@
| [`space-before-function-paren`] | 🌟 | [`space-before-function-paren`][space-after-function-paren] |
| [`space-within-parens`] | 🌟 | [`space-in-parens`][space-in-parens] |
| [`switch-final-break`] | 🛑 | N/A |
-| [`type-literal-delimiter`] | ✅ | [`typescript/member-delimiter-style`] |
+| [`type-literal-delimiter`] | ✅ | [`@typescript-eslint/member-delimiter-style`] |
| [`variable-name`] | 🌟 | [2] |
| [`whitespace`] | 🔌 | Use [Prettier] |
[1] Recommended config: `["error", { blankLine: "always", prev: "*", next: "return" }]`
-[2] [`camelcase`][camelcase], [`no-underscore-dangle`][no-underscore-dangle], [`id-blacklist`][id-blacklist], and/or [`id-match`]
+[2] [`camelcase`][camelcase], [`no-underscore-dangle`][no-underscore-dangle], [`id-blacklist`][id-blacklist], and/or [`id-match`][id-match]
## tslint-microsoft-contrib rules
@@ -200,10 +200,10 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint-
### TypeScript
-| tslint-microsoft-contrib rule | | ESLint rule |
-| ----------------------------- | :-: | -------------------------------------------------- |
-| `prefer-array-literal` | 🌓 | [`typescript/no-array-constructor`] [1] |
-| `prefer-type-cast` | 🛑 | N/A |
+| tslint-microsoft-contrib rule | | ESLint rule |
+| ----------------------------- | :-: | ---------------------------------------------------------- |
+| `prefer-array-literal` | 🌓 | [`@typescript-eslint/no-array-constructor`] [1] |
+| `prefer-type-cast` | 🛑 | N/A |
[1] ESLint rule is slightly less strict, allowing `new Array()` and `Array(2)`.
@@ -282,7 +282,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint-
| `no-exec-script` | 🌓 | Use [`no-restricted-syntax`][no-restricted-syntax] |
| `no-jquery-raw-elements` | 🛑 | N/A |
| `no-unsupported-browser-code` | 🔌 | [`eslint-plugin-compat`][plugin:compat] |
-| `react-this-binding-issue` | 🛑 | |
+| `react-this-binding-issue` | 🛑 | N/A |
| `react-tsx-curly-spacing` | 🔌 | [`react/jsx-curly-spacing`] |
| `react-unused-props-and-state` | 🌓 | [`react/no-unused-state`] |
@@ -557,34 +557,34 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint-
-[`typescript/adjacent-overload-signatures`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/adjacent-overload-signatures.md
-[`typescript/ban-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/ban-types.md
-[`typescript/explicit-member-accessibility`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/explicit-member-accessibility.md
-[`typescript/member-ordering`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-ordering.md
-[`typescript/no-explicit-any`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-explicit-any.md
-[`typescript/no-empty-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-empty-interface.md
-[`typescript/no-inferrable-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-inferrable-types.md
-[`typescript/prefer-namespace-keyword`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-namespace-keyword.md
-[`typescript/no-namespace`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-namespace.md
-[`typescript/no-non-null-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-non-null-assertion.md
-[`typescript/no-triple-slash-reference`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-triple-slash-reference.md
-[`typescript/no-var-requires`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-var-requires.md
-[`typescript/type-annotation-spacing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/type-annotation-spacing.md
-[`typescript/no-misused-new`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-misused-new.md
-[`typescript/no-object-literal-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-object-literal-type-assertion.md
-[`typescript/no-this-alias`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-this-alias.md
-[`typescript/no-extraneous-class`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-extraneous-class.md
-[`typescript/no-unused-vars`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-unused-vars.md
-[`typescript/no-use-before-define`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-use-before-define.md
-[`typescript/indent`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/indent.md
-[`typescript/array-type`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/array-type.md
-[`typescript/class-name-casing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/class-name-casing.md
-[`typescript/interface-name-prefix`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/interface-name-prefix.md
-[`typescript/no-angle-bracket-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-angle-bracket-type-assertion.md
-[`typescript/no-parameter-properties`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-parameter-properties.md
-[`typescript/member-delimiter-style`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-delimiter-style.md
-[`typescript/prefer-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-interface.md
-[`typescript/no-array-constructor`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-array-constructor.md
+[`@typescript-eslint/adjacent-overload-signatures`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/adjacent-overload-signatures.md
+[`@typescript-eslint/ban-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/ban-types.md
+[`@typescript-eslint/explicit-member-accessibility`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/explicit-member-accessibility.md
+[`@typescript-eslint/member-ordering`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-ordering.md
+[`@typescript-eslint/no-explicit-any`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-explicit-any.md
+[`@typescript-eslint/no-empty-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-empty-interface.md
+[`@typescript-eslint/no-inferrable-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-inferrable-types.md
+[`@typescript-eslint/prefer-namespace-keyword`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-namespace-keyword.md
+[`@typescript-eslint/no-namespace`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-namespace.md
+[`@typescript-eslint/no-non-null-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-non-null-assertion.md
+[`@typescript-eslint/no-triple-slash-reference`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-triple-slash-reference.md
+[`@typescript-eslint/no-var-requires`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-var-requires.md
+[`@typescript-eslint/type-annotation-spacing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/type-annotation-spacing.md
+[`@typescript-eslint/no-misused-new`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-misused-new.md
+[`@typescript-eslint/no-object-literal-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-object-literal-type-assertion.md
+[`@typescript-eslint/no-this-alias`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-this-alias.md
+[`@typescript-eslint/no-extraneous-class`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-extraneous-class.md
+[`@typescript-eslint/no-unused-vars`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-unused-vars.md
+[`@typescript-eslint/no-use-before-define`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-use-before-define.md
+[`@typescript-eslint/indent`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/indent.md
+[`@typescript-eslint/array-type`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/array-type.md
+[`@typescript-eslint/class-name-casing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/class-name-casing.md
+[`@typescript-eslint/interface-name-prefix`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/interface-name-prefix.md
+[`@typescript-eslint/no-angle-bracket-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-angle-bracket-type-assertion.md
+[`@typescript-eslint/no-parameter-properties`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-parameter-properties.md
+[`@typescript-eslint/member-delimiter-style`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-delimiter-style.md
+[`@typescript-eslint/prefer-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-interface.md
+[`@typescript-eslint/no-array-constructor`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-array-constructor.md
From ba8ebb262e202103087b53c2ce3ca72c33743773 Mon Sep 17 00:00:00 2001
From: Brad Zacher
Date: Wed, 23 Jan 2019 05:04:10 -0800
Subject: [PATCH 36/88] chore: add vscode shared config files (#126)
---
.gitignore | 1 -
.vscode/extensions.json | 8 ++++++++
.vscode/launch.json | 21 +++++++++++++++++++++
.vscode/settings.json | 26 ++++++++++++++++++++++++++
4 files changed, 55 insertions(+), 1 deletion(-)
create mode 100644 .vscode/extensions.json
create mode 100644 .vscode/launch.json
create mode 100644 .vscode/settings.json
diff --git a/.gitignore b/.gitignore
index 213ae9c36aa4..41847c7fd604 100644
--- a/.gitignore
+++ b/.gitignore
@@ -61,6 +61,5 @@ typings/
.next
.DS_Store
-.vscode
.idea
dist
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 000000000000..0a2e1c827047
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,8 @@
+{
+ "recommendations": [
+ "esbenp.prettier-vscode",
+ "dbaeumer.vscode-eslint",
+ "editorconfig.editorconfig"
+ ],
+ "unwantedRecommendations": ["hookyqr.beautify", "dbaeumer.jshint"]
+}
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 000000000000..18bf27ada556
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,21 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "node",
+ "request": "launch",
+ "name": "Jest Test Current eslint-plugin Rule",
+ "cwd": "${workspaceFolder}/packages/eslint-plugin/",
+ "program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
+ "args": [
+ "--colors",
+ "${workspaceFolder}/packages/eslint-plugin/tests/lib/rules/${fileBasename}"
+ ],
+ "console": "integratedTerminal",
+ "internalConsoleOptions": "neverOpen"
+ }
+ ]
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 000000000000..adcf2422e8f3
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,26 @@
+
+{
+ // An array of language ids which should be validated by ESLint
+ "eslint.validate": [
+ "javascript",
+ "javascriptreact",
+ {
+ "language": "typescript",
+ "autoFix": true
+ },
+ {
+ "language": "typescriptreact",
+ "autoFix": true
+ }
+ ],
+
+ // When enabled, will trim trailing whitespace when saving a file.
+ "files.trimTrailingWhitespace": true,
+
+ // typescript auto-format settings
+ "typescript.tsdk": "node_modules/typescript/lib",
+ "javascript.preferences.importModuleSpecifier": "auto",
+ "typescript.preferences.importModuleSpecifier": "auto",
+ "javascript.preferences.quoteStyle": "single",
+ "typescript.preferences.quoteStyle": "single"
+}
From aa9d1e175c8dc6fc4b8c4db47648120478a71ba7 Mon Sep 17 00:00:00 2001
From: James Henry
Date: Wed, 23 Jan 2019 08:54:50 -0500
Subject: [PATCH 37/88] fix(eslint-plugin): make parser services error clearer
(#132)
---
packages/eslint-plugin/README.md | 89 +++++++++++--------
packages/eslint-plugin/lib/util.js | 6 +-
.../tests/lib/rules/restrict-plus-operands.js | 1 -
packages/parser/README.md | 11 ++-
4 files changed, 68 insertions(+), 39 deletions(-)
diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md
index 108dd0f994be..4f6f771d47c4 100644
--- a/packages/eslint-plugin/README.md
+++ b/packages/eslint-plugin/README.md
@@ -51,6 +51,23 @@ You can also enable all the recommended rules at once. Add `plugin:@typescript-e
}
```
+If you want to use rules which require type information, you will need to specify a path to your tsconfig.json file in the "project" property of "parserOptions".
+
+```json
+{
+ "parser": "@typescript-eslint/parser",
+ "parserOptions": {
+ "project": "./tsconfig.json"
+ },
+ "plugins": ["@typescript-eslint"],
+ "rules": {
+ "@typescript-eslint/restrict-plus-operands": "error"
+ }
+}
+```
+
+See [@typescript-eslint/parser's README.md](../parser/README.md) for more information on the available "parserOptions".
+
## Supported Rules
@@ -59,41 +76,41 @@ You can also enable all the recommended rules at once. Add `plugin:@typescript-e
**Key**: :heavy_check_mark: = recommended, :wrench: = fixable
-| Name | Description | :heavy_check_mark: | :wrench: |
-| ---- | ----------- | ------------------ | -------- |
-| [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive (`adjacent-overload-signatures` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Requires using either `T[]` or `Array` for arrays (`array-type` from TSLint) | :heavy_check_mark: | :wrench: |
-| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Enforces that types will not to be used (`ban-types` from TSLint) | :heavy_check_mark: | :wrench: |
-| [`@typescript-eslint/camelcase`](./docs/rules/camelcase.md) | Enforce camelCase naming convention | :heavy_check_mark: | |
-| [`@typescript-eslint/class-name-casing`](./docs/rules/class-name-casing.md) | Require PascalCased class and interface names (`class-name` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | :heavy_check_mark: | |
-| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/generic-type-naming`](./docs/rules/generic-type-naming.md) | Enforces naming of generic type variables | | |
-| [`@typescript-eslint/indent`](./docs/rules/indent.md) | Enforce consistent indentation (`indent` from TSLint) | :heavy_check_mark: | :wrench: |
-| [`@typescript-eslint/interface-name-prefix`](./docs/rules/interface-name-prefix.md) | Require that interface names be prefixed with `I` (`interface-name` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | :heavy_check_mark: | :wrench: |
-| [`@typescript-eslint/member-naming`](./docs/rules/member-naming.md) | Enforces naming conventions for class members by visibility. | | |
-| [`@typescript-eslint/member-ordering`](./docs/rules/member-ordering.md) | Require a consistent member declaration order (`member-ordering` from TSLint) | | |
-| [`@typescript-eslint/no-angle-bracket-type-assertion`](./docs/rules/no-angle-bracket-type-assertion.md) | Enforces the use of `as Type` assertions instead of `` assertions (`no-angle-bracket-type-assertion` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-array-constructor`](./docs/rules/no-array-constructor.md) | Disallow generic `Array` constructors | :heavy_check_mark: | :wrench: |
-| [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces (`no-empty-interface` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type (`no-any` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Forbids the use of classes as namespaces (`no-unnecessary-class` from TSLint) | | |
-| [`@typescript-eslint/no-inferrable-types`](./docs/rules/no-inferrable-types.md) | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean. (`no-inferrable-types` from TSLint) | :heavy_check_mark: | :wrench: |
-| [`@typescript-eslint/no-misused-new`](./docs/rules/no-misused-new.md) | Enforce valid definition of `new` and `constructor`. (`no-misused-new` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-namespace`](./docs/rules/no-namespace.md) | Disallow the use of custom TypeScript modules and namespaces (`no-namespace` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-non-null-assertion`](./docs/rules/no-non-null-assertion.md) | Disallows non-null assertions using the `!` postfix operator (`no-non-null-assertion` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-object-literal-type-assertion`](./docs/rules/no-object-literal-type-assertion.md) | Forbids an object literal to appear in a type assertion expression (`no-object-literal-type-assertion` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-parameter-properties`](./docs/rules/no-parameter-properties.md) | Disallow the use of parameter properties in class constructors. (`no-parameter-properties` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` (`no-this-assignment` from TSLint) | | |
-| [`@typescript-eslint/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) | Disallow `/// ` comments (`no-reference` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases (`interface-over-type-literal` from TSLint) | | |
-| [`@typescript-eslint/no-unused-vars`](./docs/rules/no-unused-vars.md) | Disallow unused variables (`no-unused-variable` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | :heavy_check_mark: | |
-| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements (`no-var-requires` from TSLint) | :heavy_check_mark: | |
-| [`@typescript-eslint/prefer-interface`](./docs/rules/prefer-interface.md) | Prefer an interface declaration over a type literal (type T = { ... }) (`interface-over-type-literal` from TSLint) | :heavy_check_mark: | :wrench: |
-| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (`no-internal-module` from TSLint) | :heavy_check_mark: | :wrench: |
-| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string. (`restrict-plus-operands` from TSLint) | | |
-| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations (`typedef-whitespace` from TSLint) | :heavy_check_mark: | :wrench: |
+| Name | Description | :heavy_check_mark: | :wrench: |
+| --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -------- |
+| [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive (`adjacent-overload-signatures` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Requires using either `T[]` or `Array` for arrays (`array-type` from TSLint) | :heavy_check_mark: | :wrench: |
+| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Enforces that types will not to be used (`ban-types` from TSLint) | :heavy_check_mark: | :wrench: |
+| [`@typescript-eslint/camelcase`](./docs/rules/camelcase.md) | Enforce camelCase naming convention | :heavy_check_mark: | |
+| [`@typescript-eslint/class-name-casing`](./docs/rules/class-name-casing.md) | Require PascalCased class and interface names (`class-name` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | :heavy_check_mark: | |
+| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/generic-type-naming`](./docs/rules/generic-type-naming.md) | Enforces naming of generic type variables | | |
+| [`@typescript-eslint/indent`](./docs/rules/indent.md) | Enforce consistent indentation (`indent` from TSLint) | :heavy_check_mark: | :wrench: |
+| [`@typescript-eslint/interface-name-prefix`](./docs/rules/interface-name-prefix.md) | Require that interface names be prefixed with `I` (`interface-name` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | :heavy_check_mark: | :wrench: |
+| [`@typescript-eslint/member-naming`](./docs/rules/member-naming.md) | Enforces naming conventions for class members by visibility. | | |
+| [`@typescript-eslint/member-ordering`](./docs/rules/member-ordering.md) | Require a consistent member declaration order (`member-ordering` from TSLint) | | |
+| [`@typescript-eslint/no-angle-bracket-type-assertion`](./docs/rules/no-angle-bracket-type-assertion.md) | Enforces the use of `as Type` assertions instead of `` assertions (`no-angle-bracket-type-assertion` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-array-constructor`](./docs/rules/no-array-constructor.md) | Disallow generic `Array` constructors | :heavy_check_mark: | :wrench: |
+| [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces (`no-empty-interface` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type (`no-any` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Forbids the use of classes as namespaces (`no-unnecessary-class` from TSLint) | | |
+| [`@typescript-eslint/no-inferrable-types`](./docs/rules/no-inferrable-types.md) | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean. (`no-inferrable-types` from TSLint) | :heavy_check_mark: | :wrench: |
+| [`@typescript-eslint/no-misused-new`](./docs/rules/no-misused-new.md) | Enforce valid definition of `new` and `constructor`. (`no-misused-new` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-namespace`](./docs/rules/no-namespace.md) | Disallow the use of custom TypeScript modules and namespaces (`no-namespace` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-non-null-assertion`](./docs/rules/no-non-null-assertion.md) | Disallows non-null assertions using the `!` postfix operator (`no-non-null-assertion` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-object-literal-type-assertion`](./docs/rules/no-object-literal-type-assertion.md) | Forbids an object literal to appear in a type assertion expression (`no-object-literal-type-assertion` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-parameter-properties`](./docs/rules/no-parameter-properties.md) | Disallow the use of parameter properties in class constructors. (`no-parameter-properties` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` (`no-this-assignment` from TSLint) | | |
+| [`@typescript-eslint/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) | Disallow `/// ` comments (`no-reference` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases (`interface-over-type-literal` from TSLint) | | |
+| [`@typescript-eslint/no-unused-vars`](./docs/rules/no-unused-vars.md) | Disallow unused variables (`no-unused-variable` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | :heavy_check_mark: | |
+| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements (`no-var-requires` from TSLint) | :heavy_check_mark: | |
+| [`@typescript-eslint/prefer-interface`](./docs/rules/prefer-interface.md) | Prefer an interface declaration over a type literal (type T = { ... }) (`interface-over-type-literal` from TSLint) | :heavy_check_mark: | :wrench: |
+| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (`no-internal-module` from TSLint) | :heavy_check_mark: | :wrench: |
+| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string. (`restrict-plus-operands` from TSLint) | | |
+| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations (`typedef-whitespace` from TSLint) | :heavy_check_mark: | :wrench: |
diff --git a/packages/eslint-plugin/lib/util.js b/packages/eslint-plugin/lib/util.js
index 1df02bfb9e8e..e12e15f80413 100644
--- a/packages/eslint-plugin/lib/util.js
+++ b/packages/eslint-plugin/lib/util.js
@@ -117,8 +117,12 @@ exports.getParserServices = context => {
!context.parserServices.program ||
!context.parserServices.esTreeNodeToTSNodeMap
) {
+ /**
+ * The user needs to have configured "project" in their parserOptions
+ * for @typescript-eslint/parser
+ */
throw new Error(
- 'This rule requires you to use `@typescript-eslint/parser`.'
+ `You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.`
);
}
return context.parserServices;
diff --git a/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js b/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js
index a13b7cea3e47..d5a07e596982 100644
--- a/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js
+++ b/packages/eslint-plugin/tests/lib/rules/restrict-plus-operands.js
@@ -22,7 +22,6 @@ const rootPath = path.join(process.cwd(), 'tests/fixtures/');
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
- generateServices: true,
tsconfigRootDir: rootPath,
project: './tsconfig.json'
}
diff --git a/packages/parser/README.md b/packages/parser/README.md
index f348ae4617dc..d0a6879b4e57 100644
--- a/packages/parser/README.md
+++ b/packages/parser/README.md
@@ -48,6 +48,12 @@ The following additional configuration options are available by specifying them
- **`useJSXTextNode`** - default `true`. Please set `false` if you use this parser on ESLint v4. If this is `false`, the parser creates the AST of JSX texts as the legacy style.
+- **`project`** - default `undefined`. This option allows you to provide a path to your project's `tsconfig.json`. **This setting is required if you want to use rules which require type information**. You may want to use this setting in tandem with the `tsconfigRootDir` option below.
+
+- **`tsconfigRootDir`** - default `undefined`. This option allows you to provide the root directory for relative tsconfig paths specified in the `project` option above.
+
+- **`extraFileExtensions`** - default `undefined`. This option allows you to provide one or more additional file extensions which should be considered in the TypeScript Program compilation. E.g. a `.vue` file
+
### .eslintrc.json
```json
@@ -57,7 +63,10 @@ The following additional configuration options are available by specifying them
"ecmaFeatures": {
"jsx": true
},
- "useJSXTextNode": true
+ "useJSXTextNode": true,
+ "project": "./tsconfig.json",
+ "tsconfigRootDir": "../../",
+ "extraFileExtensions": [".vue"]
}
}
```
From d8243b41893b0423bb0b29c99e076e1c4162a7a5 Mon Sep 17 00:00:00 2001
From: Armano
Date: Thu, 24 Jan 2019 14:03:11 +0100
Subject: [PATCH 38/88] fix(ts-estree): include modifiers in exported node
range (#133)
---
.../lib/__snapshots__/javascript.ts.snap | 1006 ++++++++++++++++-
.../lib/__snapshots__/typescript.ts.snap | 28 +-
.../export-async-named-function.src.js | 1 +
.../javascript/modules/export-const.src.js | 1 +
...export-default-async-named-function.src.js | 1 +
.../javascript/modules/export-let.src.js | 1 +
packages/typescript-estree/src/node-utils.ts | 14 +-
.../tests/ast-alignment/fixtures-to-test.ts | 9 +-
.../lib/__snapshots__/javascript.ts.snap | 1002 +++++++++++++++-
.../semantic-diagnostics-enabled.ts.snap | 8 +
.../lib/__snapshots__/typescript.ts.snap | 28 +-
11 files changed, 2019 insertions(+), 80 deletions(-)
create mode 100644 packages/shared-fixtures/fixtures/javascript/modules/export-async-named-function.src.js
create mode 100644 packages/shared-fixtures/fixtures/javascript/modules/export-const.src.js
create mode 100644 packages/shared-fixtures/fixtures/javascript/modules/export-default-async-named-function.src.js
create mode 100644 packages/shared-fixtures/fixtures/javascript/modules/export-let.src.js
diff --git a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap
index b31c5e710a2b..3dc1ea581abe 100644
--- a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap
@@ -105637,15 +105637,677 @@ Object {
}
`;
+exports[`javascript fixtures/modules/export-async-named-function.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declaration": Object {
+ "async": true,
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 28,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 28,
+ 30,
+ ],
+ "type": "BlockStatement",
+ },
+ "expression": false,
+ "generator": false,
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 25,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 22,
+ 25,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "params": Array [],
+ "range": Array [
+ 7,
+ 30,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 30,
+ ],
+ "source": null,
+ "specifiers": Array [],
+ "type": "ExportNamedDeclaration",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 31,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 6,
+ ],
+ "type": "Keyword",
+ "value": "export",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 12,
+ ],
+ "type": "Identifier",
+ "value": "async",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 21,
+ ],
+ "type": "Keyword",
+ "value": "function",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 25,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 22,
+ 25,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 26,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 25,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 25,
+ 26,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 27,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 26,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 26,
+ 27,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 29,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 28,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 28,
+ 29,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 29,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 29,
+ 30,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
+exports[`javascript fixtures/modules/export-const.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declaration": Object {
+ "declarations": Array [
+ Object {
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 13,
+ 16,
+ ],
+ "type": "Identifier",
+ },
+ "init": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 20,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 19,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 19,
+ 20,
+ ],
+ "raw": "2",
+ "type": "Literal",
+ "value": 2,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 20,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 20,
+ ],
+ "type": "VariableDeclarator",
+ },
+ ],
+ "kind": "const",
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 21,
+ ],
+ "type": "VariableDeclaration",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 21,
+ ],
+ "source": null,
+ "specifiers": Array [],
+ "type": "ExportNamedDeclaration",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 22,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 6,
+ ],
+ "type": "Keyword",
+ "value": "export",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 12,
+ ],
+ "type": "Keyword",
+ "value": "const",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 16,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 20,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 19,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 19,
+ 20,
+ ],
+ "type": "Numeric",
+ "value": "2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`javascript fixtures/modules/export-default-array.src 1`] = `
Object {
"body": Array [
Object {
"declaration": Object {
- "elements": Array [],
+ "elements": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 17,
+ ],
+ "type": "ArrayExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 18,
+ ],
+ "type": "ExportDefaultDeclaration",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 19,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 6,
+ ],
+ "type": "Keyword",
+ "value": "export",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 14,
+ ],
+ "type": "Keyword",
+ "value": "default",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": "[",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 16,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 16,
+ 17,
+ ],
+ "type": "Punctuator",
+ "value": "]",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
+exports[`javascript fixtures/modules/export-default-async-named-function.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declaration": Object {
+ "async": true,
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 36,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 36,
+ 38,
+ ],
+ "type": "BlockStatement",
+ },
+ "expression": false,
+ "generator": false,
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 33,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 30,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 30,
+ 33,
+ ],
+ "type": "Identifier",
+ },
"loc": Object {
"end": Object {
- "column": 17,
+ "column": 38,
"line": 1,
},
"start": Object {
@@ -105653,15 +106315,16 @@ Object {
"line": 1,
},
},
+ "params": Array [],
"range": Array [
15,
- 17,
+ 38,
],
- "type": "ArrayExpression",
+ "type": "FunctionDeclaration",
},
"loc": Object {
"end": Object {
- "column": 18,
+ "column": 38,
"line": 1,
},
"start": Object {
@@ -105671,7 +106334,7 @@ Object {
},
"range": Array [
0,
- 18,
+ 38,
],
"type": "ExportDefaultDeclaration",
},
@@ -105689,7 +106352,7 @@ Object {
},
"range": Array [
0,
- 19,
+ 39,
],
"sourceType": "module",
"tokens": Array [
@@ -105732,56 +106395,128 @@ Object {
Object {
"loc": Object {
"end": Object {
- "column": 16,
+ "column": 20,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 20,
+ ],
+ "type": "Identifier",
+ "value": "async",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 29,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 21,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 21,
+ 29,
+ ],
+ "type": "Keyword",
+ "value": "function",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 33,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 30,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 30,
+ 33,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 34,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 33,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 33,
+ 34,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 35,
"line": 1,
},
"start": Object {
- "column": 15,
+ "column": 34,
"line": 1,
},
},
"range": Array [
- 15,
- 16,
+ 34,
+ 35,
],
"type": "Punctuator",
- "value": "[",
+ "value": ")",
},
Object {
"loc": Object {
"end": Object {
- "column": 17,
+ "column": 37,
"line": 1,
},
"start": Object {
- "column": 16,
+ "column": 36,
"line": 1,
},
},
"range": Array [
- 16,
- 17,
+ 36,
+ 37,
],
"type": "Punctuator",
- "value": "]",
+ "value": "{",
},
Object {
"loc": Object {
"end": Object {
- "column": 18,
+ "column": 38,
"line": 1,
},
"start": Object {
- "column": 17,
+ "column": 37,
"line": 1,
},
},
"range": Array [
- 17,
- 18,
+ 37,
+ 38,
],
"type": "Punctuator",
- "value": ";",
+ "value": "}",
},
],
"type": "Program",
@@ -109520,6 +110255,233 @@ Object {
}
`;
+exports[`javascript fixtures/modules/export-let.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declaration": Object {
+ "declarations": Array [
+ Object {
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 11,
+ 14,
+ ],
+ "type": "Identifier",
+ },
+ "init": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "raw": "2",
+ "type": "Literal",
+ "value": 2,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 11,
+ 18,
+ ],
+ "type": "VariableDeclarator",
+ },
+ ],
+ "kind": "let",
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 19,
+ ],
+ "type": "VariableDeclaration",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 19,
+ ],
+ "source": null,
+ "specifiers": Array [],
+ "type": "ExportNamedDeclaration",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 20,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 6,
+ ],
+ "type": "Keyword",
+ "value": "export",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 10,
+ ],
+ "type": "Keyword",
+ "value": "let",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 11,
+ 14,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Numeric",
+ "value": "2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 18,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`javascript fixtures/modules/export-named-as-default.src 1`] = `
Object {
"body": Array [
diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
index 39c74ab7586d..e2dfa3efa430 100644
--- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
@@ -814,12 +814,12 @@ Object {
"line": 3,
},
"start": Object {
- "column": 16,
+ "column": 7,
"line": 1,
},
},
"range": Array [
- 16,
+ 7,
68,
],
"superClass": null,
@@ -1262,12 +1262,12 @@ Object {
"line": 3,
},
"start": Object {
- "column": 16,
+ "column": 7,
"line": 1,
},
},
"range": Array [
- 16,
+ 7,
86,
],
"superClass": null,
@@ -2567,12 +2567,12 @@ Object {
"line": 3,
},
"start": Object {
- "column": 16,
+ "column": 7,
"line": 1,
},
},
"range": Array [
- 16,
+ 7,
78,
],
"superClass": null,
@@ -2955,12 +2955,12 @@ Object {
"line": 2,
},
"start": Object {
- "column": 16,
+ "column": 7,
"line": 1,
},
},
"range": Array [
- 16,
+ 7,
31,
],
"type": "TSInterfaceDeclaration",
@@ -35463,7 +35463,7 @@ Object {
"line": 4,
},
"start": Object {
- "column": 21,
+ "column": 7,
"line": 1,
},
},
@@ -35559,7 +35559,7 @@ Object {
},
],
"range": Array [
- 21,
+ 7,
54,
],
"type": "TSEnumDeclaration",
@@ -35851,7 +35851,7 @@ Object {
"line": 4,
},
"start": Object {
- "column": 15,
+ "column": 7,
"line": 1,
},
},
@@ -35947,7 +35947,7 @@ Object {
},
],
"range": Array [
- 15,
+ 7,
48,
],
"type": "TSEnumDeclaration",
@@ -89438,7 +89438,7 @@ Object {
"line": 1,
},
"start": Object {
- "column": 63,
+ "column": 7,
"line": 1,
},
},
@@ -89565,7 +89565,7 @@ Object {
},
],
"range": Array [
- 63,
+ 7,
72,
],
"type": "TSEnumDeclaration",
diff --git a/packages/shared-fixtures/fixtures/javascript/modules/export-async-named-function.src.js b/packages/shared-fixtures/fixtures/javascript/modules/export-async-named-function.src.js
new file mode 100644
index 000000000000..7c26b9ed6873
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/javascript/modules/export-async-named-function.src.js
@@ -0,0 +1 @@
+export async function foo() {}
diff --git a/packages/shared-fixtures/fixtures/javascript/modules/export-const.src.js b/packages/shared-fixtures/fixtures/javascript/modules/export-const.src.js
new file mode 100644
index 000000000000..cc57a55e257d
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/javascript/modules/export-const.src.js
@@ -0,0 +1 @@
+export const foo = 2;
diff --git a/packages/shared-fixtures/fixtures/javascript/modules/export-default-async-named-function.src.js b/packages/shared-fixtures/fixtures/javascript/modules/export-default-async-named-function.src.js
new file mode 100644
index 000000000000..c40a5f27d267
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/javascript/modules/export-default-async-named-function.src.js
@@ -0,0 +1 @@
+export default async function foo() {}
diff --git a/packages/shared-fixtures/fixtures/javascript/modules/export-let.src.js b/packages/shared-fixtures/fixtures/javascript/modules/export-let.src.js
new file mode 100644
index 000000000000..a3bcdb0d8122
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/javascript/modules/export-let.src.js
@@ -0,0 +1 @@
+export let foo = 2;
diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts
index 240c4d1c9f71..c844cf7ed20d 100644
--- a/packages/typescript-estree/src/node-utils.ts
+++ b/packages/typescript-estree/src/node-utils.ts
@@ -485,12 +485,14 @@ export function fixExports(
): ESTreeNode {
// check for exports
if (node.modifiers && node.modifiers[0].kind === SyntaxKind.ExportKeyword) {
- const exportKeyword = node.modifiers[0],
- nextModifier = node.modifiers[1],
- lastModifier = node.modifiers[node.modifiers.length - 1],
- declarationIsDefault =
- nextModifier && nextModifier.kind === SyntaxKind.DefaultKeyword,
- varToken = findNextToken(lastModifier, ast, ast);
+ const exportKeyword = node.modifiers[0];
+ const nextModifier = node.modifiers[1];
+ const declarationIsDefault =
+ nextModifier && nextModifier.kind === SyntaxKind.DefaultKeyword;
+
+ const varToken = declarationIsDefault
+ ? findNextToken(nextModifier, ast, ast)
+ : findNextToken(exportKeyword, ast, ast);
result.range[0] = varToken!.getStart(ast);
result.loc = getLocFor(result.range[0], result.range[1], ast);
diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
index 3b1a21e43d80..522cc53a3351 100644
--- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
+++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
@@ -326,7 +326,6 @@ tester.addFixturePatternConfig('typescript/basics', {
/**
* there is difference in range between babel and ts-estree
*/
- 'export-declare-const-named-enum',
'interface-with-optional-properties',
/**
* Babel parses it as TSQualifiedName
@@ -358,7 +357,13 @@ tester.addFixturePatternConfig('typescript/basics', {
* Babel parses this incorrectly
* https://github.com/babel/babel/issues/9324
*/
- 'type-assertion-arrow-function'
+ 'type-assertion-arrow-function',
+ /**
+ * Babel does not include range of declare keyword into enum range
+ * https://github.com/babel/babel/issues/9399
+ */
+ 'export-declare-const-named-enum',
+ 'export-declare-named-enum'
],
ignoreSourceType: [
/**
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap
index 8d02532b8d7f..5a57277c9353 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap
@@ -105312,15 +105312,674 @@ Object {
}
`;
+exports[`javascript fixtures/modules/export-async-named-function.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declaration": Object {
+ "async": true,
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 28,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 28,
+ 30,
+ ],
+ "type": "BlockStatement",
+ },
+ "expression": false,
+ "generator": false,
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 25,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 22,
+ 25,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "params": Array [],
+ "range": Array [
+ 7,
+ 30,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 30,
+ ],
+ "source": null,
+ "specifiers": Array [],
+ "type": "ExportNamedDeclaration",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 31,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 6,
+ ],
+ "type": "Keyword",
+ "value": "export",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 12,
+ ],
+ "type": "Identifier",
+ "value": "async",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 21,
+ ],
+ "type": "Keyword",
+ "value": "function",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 25,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 22,
+ 25,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 26,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 25,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 25,
+ 26,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 27,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 26,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 26,
+ 27,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 29,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 28,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 28,
+ 29,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 29,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 29,
+ 30,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
+exports[`javascript fixtures/modules/export-const.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declaration": Object {
+ "declarations": Array [
+ Object {
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 13,
+ 16,
+ ],
+ "type": "Identifier",
+ },
+ "init": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 20,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 19,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 19,
+ 20,
+ ],
+ "raw": "2",
+ "type": "Literal",
+ "value": 2,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 20,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 20,
+ ],
+ "type": "VariableDeclarator",
+ },
+ ],
+ "kind": "const",
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 21,
+ ],
+ "type": "VariableDeclaration",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 21,
+ ],
+ "source": null,
+ "specifiers": Array [],
+ "type": "ExportNamedDeclaration",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 22,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 6,
+ ],
+ "type": "Keyword",
+ "value": "export",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 12,
+ ],
+ "type": "Keyword",
+ "value": "const",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 16,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 20,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 19,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 19,
+ 20,
+ ],
+ "type": "Numeric",
+ "value": "2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`javascript fixtures/modules/export-default-array.src 1`] = `
Object {
"body": Array [
Object {
"declaration": Object {
- "elements": Array [],
+ "elements": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 17,
+ ],
+ "type": "ArrayExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 18,
+ ],
+ "type": "ExportDefaultDeclaration",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 19,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 6,
+ ],
+ "type": "Keyword",
+ "value": "export",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 14,
+ ],
+ "type": "Keyword",
+ "value": "default",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": "[",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 16,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 16,
+ 17,
+ ],
+ "type": "Punctuator",
+ "value": "]",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
+exports[`javascript fixtures/modules/export-default-async-named-function.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declaration": Object {
+ "async": true,
+ "body": Object {
+ "body": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 38,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 36,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 36,
+ 38,
+ ],
+ "type": "BlockStatement",
+ },
+ "expression": false,
+ "generator": false,
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 33,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 30,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 30,
+ 33,
+ ],
+ "type": "Identifier",
+ },
"loc": Object {
"end": Object {
- "column": 17,
+ "column": 38,
"line": 1,
},
"start": Object {
@@ -105328,15 +105987,16 @@ Object {
"line": 1,
},
},
+ "params": Array [],
"range": Array [
15,
- 17,
+ 38,
],
- "type": "ArrayExpression",
+ "type": "FunctionDeclaration",
},
"loc": Object {
"end": Object {
- "column": 18,
+ "column": 38,
"line": 1,
},
"start": Object {
@@ -105346,7 +106006,7 @@ Object {
},
"range": Array [
0,
- 18,
+ 38,
],
"type": "ExportDefaultDeclaration",
},
@@ -105363,7 +106023,7 @@ Object {
},
"range": Array [
0,
- 19,
+ 39,
],
"sourceType": "module",
"tokens": Array [
@@ -105406,56 +106066,128 @@ Object {
Object {
"loc": Object {
"end": Object {
- "column": 16,
+ "column": 20,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 20,
+ ],
+ "type": "Identifier",
+ "value": "async",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 29,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 21,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 21,
+ 29,
+ ],
+ "type": "Keyword",
+ "value": "function",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 33,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 30,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 30,
+ 33,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 34,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 33,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 33,
+ 34,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 35,
"line": 1,
},
"start": Object {
- "column": 15,
+ "column": 34,
"line": 1,
},
},
"range": Array [
- 15,
- 16,
+ 34,
+ 35,
],
"type": "Punctuator",
- "value": "[",
+ "value": ")",
},
Object {
"loc": Object {
"end": Object {
- "column": 17,
+ "column": 37,
"line": 1,
},
"start": Object {
- "column": 16,
+ "column": 36,
"line": 1,
},
},
"range": Array [
- 16,
- 17,
+ 36,
+ 37,
],
"type": "Punctuator",
- "value": "]",
+ "value": "{",
},
Object {
"loc": Object {
"end": Object {
- "column": 18,
+ "column": 38,
"line": 1,
},
"start": Object {
- "column": 17,
+ "column": 37,
"line": 1,
},
},
"range": Array [
- 17,
- 18,
+ 37,
+ 38,
],
"type": "Punctuator",
- "value": ";",
+ "value": "}",
},
],
"type": "Program",
@@ -109178,6 +109910,232 @@ Object {
}
`;
+exports[`javascript fixtures/modules/export-let.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declaration": Object {
+ "declarations": Array [
+ Object {
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 11,
+ 14,
+ ],
+ "type": "Identifier",
+ },
+ "init": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "raw": "2",
+ "type": "Literal",
+ "value": 2,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 11,
+ 18,
+ ],
+ "type": "VariableDeclarator",
+ },
+ ],
+ "kind": "let",
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 19,
+ ],
+ "type": "VariableDeclaration",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 19,
+ ],
+ "source": null,
+ "specifiers": Array [],
+ "type": "ExportNamedDeclaration",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 20,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 6,
+ ],
+ "type": "Keyword",
+ "value": "export",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 10,
+ ],
+ "type": "Keyword",
+ "value": "let",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 11,
+ 14,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Numeric",
+ "value": "2",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 18,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`javascript fixtures/modules/export-named-as-default.src 1`] = `
Object {
"body": Array [
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
index 768b79a8fd31..e680cb92473c 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
@@ -790,8 +790,14 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/error-strict.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-async-named-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-const.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-default-array.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-default-async-named-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-default-class.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-default-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
@@ -824,6 +830,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-let.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-named-as-default.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/modules/export-named-as-specifier.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
index 90ebe3e137e0..b481510bdae7 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
@@ -812,12 +812,12 @@ Object {
"line": 3,
},
"start": Object {
- "column": 16,
+ "column": 7,
"line": 1,
},
},
"range": Array [
- 16,
+ 7,
68,
],
"superClass": null,
@@ -1259,12 +1259,12 @@ Object {
"line": 3,
},
"start": Object {
- "column": 16,
+ "column": 7,
"line": 1,
},
},
"range": Array [
- 16,
+ 7,
86,
],
"superClass": null,
@@ -2561,12 +2561,12 @@ Object {
"line": 3,
},
"start": Object {
- "column": 16,
+ "column": 7,
"line": 1,
},
},
"range": Array [
- 16,
+ 7,
78,
],
"superClass": null,
@@ -2948,12 +2948,12 @@ Object {
"line": 2,
},
"start": Object {
- "column": 16,
+ "column": 7,
"line": 1,
},
},
"range": Array [
- 16,
+ 7,
31,
],
"type": "TSInterfaceDeclaration",
@@ -35398,7 +35398,7 @@ Object {
"line": 4,
},
"start": Object {
- "column": 21,
+ "column": 7,
"line": 1,
},
},
@@ -35494,7 +35494,7 @@ Object {
},
],
"range": Array [
- 21,
+ 7,
54,
],
"type": "TSEnumDeclaration",
@@ -35785,7 +35785,7 @@ Object {
"line": 4,
},
"start": Object {
- "column": 15,
+ "column": 7,
"line": 1,
},
},
@@ -35881,7 +35881,7 @@ Object {
},
],
"range": Array [
- 15,
+ 7,
48,
],
"type": "TSEnumDeclaration",
@@ -88748,7 +88748,7 @@ Object {
"line": 1,
},
"start": Object {
- "column": 63,
+ "column": 7,
"line": 1,
},
},
@@ -88875,7 +88875,7 @@ Object {
},
],
"range": Array [
- 63,
+ 7,
72,
],
"type": "TSEnumDeclaration",
From 9068b6276064e6729e1635ab11f7d70a543afa68 Mon Sep 17 00:00:00 2001
From: Armano
Date: Sat, 26 Jan 2019 00:56:41 +0100
Subject: [PATCH 39/88] fix(ts-estree): expand optional property to include
question token (#138)
---
.../tests/lib/__snapshots__/typescript.ts.snap | 12 ++++++------
packages/typescript-estree/src/convert.ts | 8 ++++++++
.../tests/ast-alignment/fixtures-to-test.ts | 4 ----
.../tests/lib/__snapshots__/typescript.ts.snap | 12 ++++++------
4 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
index e2dfa3efa430..08e944aecc31 100644
--- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
@@ -48454,7 +48454,7 @@ Object {
Object {
"loc": Object {
"end": Object {
- "column": 13,
+ "column": 14,
"line": 12,
},
"start": Object {
@@ -48466,7 +48466,7 @@ Object {
"optional": true,
"range": Array [
253,
- 254,
+ 255,
],
"type": "Identifier",
},
@@ -48544,7 +48544,7 @@ Object {
Object {
"loc": Object {
"end": Object {
- "column": 16,
+ "column": 17,
"line": 13,
},
"start": Object {
@@ -48556,7 +48556,7 @@ Object {
"optional": true,
"range": Array [
281,
- 282,
+ 283,
],
"type": "Identifier",
},
@@ -53553,7 +53553,7 @@ Object {
Object {
"loc": Object {
"end": Object {
- "column": 31,
+ "column": 32,
"line": 4,
},
"start": Object {
@@ -53565,7 +53565,7 @@ Object {
"optional": true,
"range": Array [
73,
- 76,
+ 77,
],
"type": "Identifier",
},
diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts
index 64120d6a8d85..ff365b187c7e 100644
--- a/packages/typescript-estree/src/convert.ts
+++ b/packages/typescript-estree/src/convert.ts
@@ -1315,6 +1315,14 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
}
if (node.questionToken) {
+ if (node.questionToken.end > parameter.range[1]) {
+ parameter.range[1] = node.questionToken.end;
+ parameter.loc = getLocFor(
+ parameter.range[0],
+ parameter.range[1],
+ ast
+ );
+ }
parameter.optional = true;
}
diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
index 522cc53a3351..b44faf0feb64 100644
--- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
+++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
@@ -323,10 +323,6 @@ tester.addFixturePatternConfig('typescript/basics', {
* TODO: Investigate in more depth, potentially split up different parts of the interface
*/
'interface-with-all-property-types', // babel parse errors
- /**
- * there is difference in range between babel and ts-estree
- */
- 'interface-with-optional-properties',
/**
* Babel parses it as TSQualifiedName
* ts parses it as MemberExpression
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
index b481510bdae7..c5085cf91009 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
@@ -48344,7 +48344,7 @@ Object {
Object {
"loc": Object {
"end": Object {
- "column": 13,
+ "column": 14,
"line": 12,
},
"start": Object {
@@ -48356,7 +48356,7 @@ Object {
"optional": true,
"range": Array [
253,
- 254,
+ 255,
],
"type": "Identifier",
},
@@ -48434,7 +48434,7 @@ Object {
Object {
"loc": Object {
"end": Object {
- "column": 16,
+ "column": 17,
"line": 13,
},
"start": Object {
@@ -48446,7 +48446,7 @@ Object {
"optional": true,
"range": Array [
281,
- 282,
+ 283,
],
"type": "Identifier",
},
@@ -53414,7 +53414,7 @@ Object {
Object {
"loc": Object {
"end": Object {
- "column": 31,
+ "column": 32,
"line": 4,
},
"start": Object {
@@ -53426,7 +53426,7 @@ Object {
"optional": true,
"range": Array [
73,
- 76,
+ 77,
],
"type": "Identifier",
},
From e442d280285e8acab253a5e80a7a6a6c5d1b4692 Mon Sep 17 00:00:00 2001
From: Armano
Date: Sun, 27 Jan 2019 18:00:24 +0100
Subject: [PATCH 40/88] test(ts-estree): add broken test cases (#140)
---
.../lib/__snapshots__/javascript.ts.snap | 1178 +++++++++++++++++
.../lib/__snapshots__/typescript.ts.snap | 392 ++++++
.../function/function-with-return.js | 3 +
.../function/return-multiline-sequence.src.js | 7 +
.../function/return-sequence.src.js | 3 +
...ow-function-with-optional-parameter.src.ts | 1 +
.../tests/ast-alignment/fixtures-to-test.ts | 27 +-
.../lib/__snapshots__/javascript.ts.snap | 1176 ++++++++++++++++
.../semantic-diagnostics-enabled.ts.snap | 6 +
.../lib/__snapshots__/typescript.ts.snap | 391 ++++++
10 files changed, 3175 insertions(+), 9 deletions(-)
create mode 100644 packages/shared-fixtures/fixtures/javascript/function/function-with-return.js
create mode 100644 packages/shared-fixtures/fixtures/javascript/function/return-multiline-sequence.src.js
create mode 100644 packages/shared-fixtures/fixtures/javascript/function/return-sequence.src.js
create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/arrow-function-with-optional-parameter.src.ts
diff --git a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap
index 3dc1ea581abe..6a51ccfcd4de 100644
--- a/packages/parser/tests/lib/__snapshots__/javascript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/javascript.ts.snap
@@ -99362,6 +99362,1184 @@ Object {
}
`;
+exports[`javascript fixtures/function/return-multiline-sequence.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "async": false,
+ "body": Object {
+ "body": Array [
+ Object {
+ "argument": Object {
+ "expressions": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "name": "x",
+ "range": Array [
+ 40,
+ 41,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 4,
+ },
+ },
+ "name": "y",
+ "range": Array [
+ 47,
+ 48,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 5,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 5,
+ },
+ },
+ "name": "z",
+ "range": Array [
+ 54,
+ 55,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 5,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 40,
+ 55,
+ ],
+ "type": "SequenceExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 6,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 60,
+ ],
+ "type": "ReturnStatement",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 7,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 23,
+ 62,
+ ],
+ "type": "BlockStatement",
+ },
+ "expression": false,
+ "generator": false,
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 9,
+ 12,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 7,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "name": "x",
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "name": "y",
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "name": "z",
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "range": Array [
+ 0,
+ 62,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 8,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 63,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 8,
+ ],
+ "type": "Keyword",
+ "value": "function",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 9,
+ 12,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 14,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ "value": "x",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Identifier",
+ "value": "y",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 18,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Identifier",
+ "value": "z",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 22,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 21,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 21,
+ 22,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 24,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 23,
+ 24,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 33,
+ ],
+ "type": "Keyword",
+ "value": "return",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 34,
+ 35,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 40,
+ 41,
+ ],
+ "type": "Identifier",
+ "value": "x",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 41,
+ 42,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 47,
+ 48,
+ ],
+ "type": "Identifier",
+ "value": "y",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 48,
+ 49,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 5,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 5,
+ },
+ },
+ "range": Array [
+ 54,
+ 55,
+ ],
+ "type": "Identifier",
+ "value": "z",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 6,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 6,
+ },
+ },
+ "range": Array [
+ 58,
+ 59,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 6,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 6,
+ },
+ },
+ "range": Array [
+ 59,
+ 60,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 7,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 7,
+ },
+ },
+ "range": Array [
+ 61,
+ 62,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
+exports[`javascript fixtures/function/return-sequence.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "async": false,
+ "body": Object {
+ "body": Array [
+ Object {
+ "argument": Object {
+ "expressions": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "name": "x",
+ "range": Array [
+ 35,
+ 36,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 2,
+ },
+ },
+ "name": "y",
+ "range": Array [
+ 38,
+ 39,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 16,
+ "line": 2,
+ },
+ },
+ "name": "z",
+ "range": Array [
+ 41,
+ 42,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 35,
+ 42,
+ ],
+ "type": "SequenceExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 44,
+ ],
+ "type": "ReturnStatement",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 23,
+ 46,
+ ],
+ "type": "BlockStatement",
+ },
+ "expression": false,
+ "generator": false,
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 9,
+ 12,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "name": "x",
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "name": "y",
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "name": "z",
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "range": Array [
+ 0,
+ 46,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 47,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 8,
+ ],
+ "type": "Keyword",
+ "value": "function",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 9,
+ 12,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 14,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ "value": "x",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Identifier",
+ "value": "y",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 18,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Identifier",
+ "value": "z",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 22,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 21,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 21,
+ 22,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 24,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 23,
+ 24,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 33,
+ ],
+ "type": "Keyword",
+ "value": "return",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 34,
+ 35,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 35,
+ 36,
+ ],
+ "type": "Identifier",
+ "value": "x",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 36,
+ 37,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 38,
+ 39,
+ ],
+ "type": "Identifier",
+ "value": "y",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 39,
+ 40,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 16,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 41,
+ 42,
+ ],
+ "type": "Identifier",
+ "value": "z",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 42,
+ 43,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 18,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 43,
+ 44,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 45,
+ 46,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`javascript fixtures/generators/anonymous-generator.src 1`] = `
Object {
"body": Array [
diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
index 08e944aecc31..f540948a5558 100644
--- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
@@ -3114,6 +3114,398 @@ Object {
}
`;
+exports[`typescript fixtures/basics/arrow-function-with-optional-parameter.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "expression": Object {
+ "arguments": Array [],
+ "callee": Object {
+ "async": false,
+ "body": Object {
+ "left": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "name": "k",
+ "range": Array [
+ 9,
+ 10,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "operator": "+",
+ "range": Array [
+ 9,
+ 14,
+ ],
+ "right": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 14,
+ ],
+ "raw": "1",
+ "type": "Literal",
+ "value": 1,
+ },
+ "type": "BinaryExpression",
+ },
+ "expression": true,
+ "generator": false,
+ "id": null,
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 1,
+ },
+ },
+ "name": "k",
+ "optional": true,
+ "range": Array [
+ 2,
+ 4,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "range": Array [
+ 1,
+ 14,
+ ],
+ "type": "ArrowFunctionExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 17,
+ ],
+ "type": "CallExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 18,
+ ],
+ "type": "ExpressionStatement",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 19,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 1,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 1,
+ 2,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 2,
+ 3,
+ ],
+ "type": "Identifier",
+ "value": "k",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 3,
+ 4,
+ ],
+ "type": "Punctuator",
+ "value": "?",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 4,
+ 5,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 6,
+ 8,
+ ],
+ "type": "Punctuator",
+ "value": "=>",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 9,
+ 10,
+ ],
+ "type": "Identifier",
+ "value": "k",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 11,
+ 12,
+ ],
+ "type": "Punctuator",
+ "value": "+",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 14,
+ ],
+ "type": "Numeric",
+ "value": "1",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 16,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 16,
+ 17,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`typescript fixtures/basics/arrow-function-with-type-parameters.src 1`] = `
Object {
"body": Array [
diff --git a/packages/shared-fixtures/fixtures/javascript/function/function-with-return.js b/packages/shared-fixtures/fixtures/javascript/function/function-with-return.js
new file mode 100644
index 000000000000..c98a373f0c38
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/javascript/function/function-with-return.js
@@ -0,0 +1,3 @@
+function foo () {
+ return 1;
+}
diff --git a/packages/shared-fixtures/fixtures/javascript/function/return-multiline-sequence.src.js b/packages/shared-fixtures/fixtures/javascript/function/return-multiline-sequence.src.js
new file mode 100644
index 000000000000..be3070488139
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/javascript/function/return-multiline-sequence.src.js
@@ -0,0 +1,7 @@
+function foo (x, y, z) {
+ return (
+ x,
+ y,
+ z
+ );
+}
diff --git a/packages/shared-fixtures/fixtures/javascript/function/return-sequence.src.js b/packages/shared-fixtures/fixtures/javascript/function/return-sequence.src.js
new file mode 100644
index 000000000000..3ffe77903028
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/javascript/function/return-sequence.src.js
@@ -0,0 +1,3 @@
+function foo (x, y, z) {
+ return (x, y, z);
+}
diff --git a/packages/shared-fixtures/fixtures/typescript/basics/arrow-function-with-optional-parameter.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/arrow-function-with-optional-parameter.src.ts
new file mode 100644
index 000000000000..0289f3828aa8
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/typescript/basics/arrow-function-with-optional-parameter.src.ts
@@ -0,0 +1 @@
+((k?) => k + 1)();
diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
index b44faf0feb64..e92f68f968f4 100644
--- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
+++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
@@ -167,6 +167,15 @@ tester.addFixturePatternConfig('javascript/arrowFunctions', {
'error-strict-dup-params' // babel parse errors
]
});
+tester.addFixturePatternConfig('javascript/function', {
+ ignore: [
+ /**
+ * Babel has invalid end range of multiline SequenceExpression
+ * TODO: report it to babel
+ */
+ 'return-multiline-sequence'
+ ]
+});
tester.addFixturePatternConfig('javascript/bigIntLiterals');
tester.addFixturePatternConfig('javascript/binaryLiterals');
@@ -355,11 +364,16 @@ tester.addFixturePatternConfig('typescript/basics', {
*/
'type-assertion-arrow-function',
/**
- * Babel does not include range of declare keyword into enum range
- * https://github.com/babel/babel/issues/9399
+ * PR for range of declare keyword has been merged into Babel: https://github.com/babel/babel/pull/9406
+ * TODO: remove me in next babel > 7.3.1
*/
'export-declare-const-named-enum',
- 'export-declare-named-enum'
+ 'export-declare-named-enum',
+ /**
+ * Babel does not include optional keyword into range parameter in arrow function
+ * TODO: report it to babel
+ */
+ 'arrow-function-with-optional-parameter'
],
ignoreSourceType: [
/**
@@ -418,13 +432,8 @@ tester.addFixturePatternConfig('typescript/declare', {
tester.addFixturePatternConfig('typescript/namespaces-and-modules', {
fileType: 'ts',
- ignore: [
- /**
- * Minor AST difference
- */
- 'nested-internal-module'
- ],
ignoreSourceType: [
+ 'nested-internal-module',
'module-with-default-exports',
'ambient-module-declaration-with-import',
'declare-namespace-with-exported-function'
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap
index 5a57277c9353..85045786c853 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap
@@ -99058,6 +99058,1182 @@ Object {
}
`;
+exports[`javascript fixtures/function/return-multiline-sequence.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "async": false,
+ "body": Object {
+ "body": Array [
+ Object {
+ "argument": Object {
+ "expressions": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "name": "x",
+ "range": Array [
+ 40,
+ 41,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 4,
+ },
+ },
+ "name": "y",
+ "range": Array [
+ 47,
+ 48,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 5,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 5,
+ },
+ },
+ "name": "z",
+ "range": Array [
+ 54,
+ 55,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 5,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 40,
+ 55,
+ ],
+ "type": "SequenceExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 6,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 60,
+ ],
+ "type": "ReturnStatement",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 7,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 23,
+ 62,
+ ],
+ "type": "BlockStatement",
+ },
+ "expression": false,
+ "generator": false,
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 9,
+ 12,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 7,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "name": "x",
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "name": "y",
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "name": "z",
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "range": Array [
+ 0,
+ 62,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 8,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 63,
+ ],
+ "sourceType": "script",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 8,
+ ],
+ "type": "Keyword",
+ "value": "function",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 9,
+ 12,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 14,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ "value": "x",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Identifier",
+ "value": "y",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 18,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Identifier",
+ "value": "z",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 22,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 21,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 21,
+ 22,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 24,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 23,
+ 24,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 33,
+ ],
+ "type": "Keyword",
+ "value": "return",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 34,
+ 35,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 40,
+ 41,
+ ],
+ "type": "Identifier",
+ "value": "x",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 41,
+ 42,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 47,
+ 48,
+ ],
+ "type": "Identifier",
+ "value": "y",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 4,
+ },
+ },
+ "range": Array [
+ 48,
+ 49,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 5,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 5,
+ },
+ },
+ "range": Array [
+ 54,
+ 55,
+ ],
+ "type": "Identifier",
+ "value": "z",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 6,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 6,
+ },
+ },
+ "range": Array [
+ 58,
+ 59,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 6,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 6,
+ },
+ },
+ "range": Array [
+ 59,
+ 60,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 7,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 7,
+ },
+ },
+ "range": Array [
+ 61,
+ 62,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
+exports[`javascript fixtures/function/return-sequence.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "async": false,
+ "body": Object {
+ "body": Array [
+ Object {
+ "argument": Object {
+ "expressions": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "name": "x",
+ "range": Array [
+ 35,
+ 36,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 2,
+ },
+ },
+ "name": "y",
+ "range": Array [
+ 38,
+ 39,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 16,
+ "line": 2,
+ },
+ },
+ "name": "z",
+ "range": Array [
+ 41,
+ 42,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 35,
+ 42,
+ ],
+ "type": "SequenceExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 44,
+ ],
+ "type": "ReturnStatement",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 23,
+ 46,
+ ],
+ "type": "BlockStatement",
+ },
+ "expression": false,
+ "generator": false,
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "name": "foo",
+ "range": Array [
+ 9,
+ 12,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "name": "x",
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "name": "y",
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Identifier",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "name": "z",
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "range": Array [
+ 0,
+ 46,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 47,
+ ],
+ "sourceType": "script",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 8,
+ ],
+ "type": "Keyword",
+ "value": "function",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 9,
+ 12,
+ ],
+ "type": "Identifier",
+ "value": "foo",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 14,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ "value": "x",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Identifier",
+ "value": "y",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 18,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 20,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 20,
+ 21,
+ ],
+ "type": "Identifier",
+ "value": "z",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 22,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 21,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 21,
+ 22,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 24,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 23,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 23,
+ 24,
+ ],
+ "type": "Punctuator",
+ "value": "{",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 33,
+ ],
+ "type": "Keyword",
+ "value": "return",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 34,
+ 35,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 35,
+ 36,
+ ],
+ "type": "Identifier",
+ "value": "x",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 36,
+ 37,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 38,
+ 39,
+ ],
+ "type": "Identifier",
+ "value": "y",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 39,
+ 40,
+ ],
+ "type": "Punctuator",
+ "value": ",",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 16,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 41,
+ 42,
+ ],
+ "type": "Identifier",
+ "value": "z",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 42,
+ 43,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 19,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 18,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 43,
+ 44,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 45,
+ 46,
+ ],
+ "type": "Punctuator",
+ "value": "}",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`javascript fixtures/generators/anonymous-generator.src 1`] = `
Object {
"body": Array [
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
index e680cb92473c..1db62d5b9140 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
@@ -739,6 +739,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/forOf/invalid-for-of-with-let-and-no-braces.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/function/return-multiline-sequence.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/function/return-sequence.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/generators/anonymous-generator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/generators/async-generator-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
@@ -1887,6 +1891,8 @@ Object {
}
`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/arrow-function-with-optional-parameter.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/arrow-function-with-type-parameters.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/async-function-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
index c5085cf91009..b807e63a8220 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
@@ -3106,6 +3106,397 @@ Object {
}
`;
+exports[`typescript fixtures/basics/arrow-function-with-optional-parameter.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "expression": Object {
+ "arguments": Array [],
+ "callee": Object {
+ "async": false,
+ "body": Object {
+ "left": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "name": "k",
+ "range": Array [
+ 9,
+ 10,
+ ],
+ "type": "Identifier",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "operator": "+",
+ "range": Array [
+ 9,
+ 14,
+ ],
+ "right": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 14,
+ ],
+ "raw": "1",
+ "type": "Literal",
+ "value": 1,
+ },
+ "type": "BinaryExpression",
+ },
+ "expression": true,
+ "generator": false,
+ "id": null,
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "params": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 1,
+ },
+ },
+ "name": "k",
+ "optional": true,
+ "range": Array [
+ 2,
+ 4,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "range": Array [
+ 1,
+ 14,
+ ],
+ "type": "ArrowFunctionExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 17,
+ ],
+ "type": "CallExpression",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 18,
+ ],
+ "type": "ExpressionStatement",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 19,
+ ],
+ "sourceType": "script",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 1,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 1,
+ 2,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 2,
+ 3,
+ ],
+ "type": "Identifier",
+ "value": "k",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 3,
+ 4,
+ ],
+ "type": "Punctuator",
+ "value": "?",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 4,
+ 5,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 6,
+ 8,
+ ],
+ "type": "Punctuator",
+ "value": "=>",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 9,
+ 10,
+ ],
+ "type": "Identifier",
+ "value": "k",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 11,
+ 12,
+ ],
+ "type": "Punctuator",
+ "value": "+",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 14,
+ ],
+ "type": "Numeric",
+ "value": "1",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 16,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 15,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 15,
+ 16,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 17,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 16,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 16,
+ 17,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 18,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 17,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 17,
+ 18,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`typescript fixtures/basics/arrow-function-with-type-parameters.src 1`] = `
Object {
"body": Array [
From 5e1600308d7121fd986181cc8db589c9573d0d31 Mon Sep 17 00:00:00 2001
From: Armano
Date: Sun, 27 Jan 2019 18:06:26 +0100
Subject: [PATCH 41/88] fix(parser): add visiting of type parameters in
JSXOpeningElement (#150)
---
.../tests/lib/rules/no-unused-vars.js | 15 +-
packages/parser/src/analyze-scope.ts | 9 +
packages/parser/src/visitor-keys.ts | 7 +
.../fixtures/scope-analysis/import-keyword.ts | 1 +
.../scope-analysis/typed-jsx-element.tsx | 1 +
.../lib/__snapshots__/scope-analysis.ts.snap | 312 ++++++++++++++++++
packages/parser/tests/lib/scope-analysis.ts | 8 +-
packages/parser/tests/lib/visitor-keys.ts | 28 ++
packages/typescript-estree/package.json | 1 +
9 files changed, 379 insertions(+), 3 deletions(-)
create mode 100644 packages/parser/tests/fixtures/scope-analysis/import-keyword.ts
create mode 100644 packages/parser/tests/fixtures/scope-analysis/typed-jsx-element.tsx
create mode 100644 packages/parser/tests/lib/visitor-keys.ts
diff --git a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
index 726f755c3956..2fe854b2c442 100644
--- a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
+++ b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
@@ -557,7 +557,20 @@ export interface Bar extends foo.i18n {}
import foo from 'foo';
import bar from 'foo';
export interface Bar extends foo.i18n {}
- `
+ `,
+ // https://github.com/typescript-eslint/typescript-eslint/issues/141
+ {
+ filename: 'test.tsx',
+ code: `
+import { TypeA } from './interface';
+export const a = />;
+ `,
+ parserOptions: {
+ ecmaFeatures: {
+ jsx: true
+ }
+ }
+ }
],
invalid: [
diff --git a/packages/parser/src/analyze-scope.ts b/packages/parser/src/analyze-scope.ts
index dc17e977683b..eb9f3c92c752 100644
--- a/packages/parser/src/analyze-scope.ts
+++ b/packages/parser/src/analyze-scope.ts
@@ -235,6 +235,15 @@ class Referencer extends OriginalReferencer {
}
}
+ /**
+ * Override.
+ */
+ JSXOpeningElement(node: any) {
+ this.visit(node.name);
+ this.visitTypeParameters(node);
+ this.visit(node.attributes);
+ }
+
/**
* Override.
* Don't create the reference object in the type mode.
diff --git a/packages/parser/src/visitor-keys.ts b/packages/parser/src/visitor-keys.ts
index d1dd5e616aeb..d3938529e820 100644
--- a/packages/parser/src/visitor-keys.ts
+++ b/packages/parser/src/visitor-keys.ts
@@ -1,6 +1,8 @@
import eslintVisitorKeys from 'eslint-visitor-keys';
export const visitorKeys = eslintVisitorKeys.unionWith({
+ // Additional estree nodes.
+ Import: [],
// Additional Properties.
ArrayPattern: ['elements', 'typeAnnotation'],
ArrowFunctionExpression: ['typeParameters', 'params', 'returnType', 'body'],
@@ -30,6 +32,11 @@ export const visitorKeys = eslintVisitorKeys.unionWith({
RestElement: ['argument', 'typeAnnotation'],
NewExpression: ['callee', 'typeParameters', 'arguments'],
CallExpression: ['callee', 'typeParameters', 'arguments'],
+ // JSX
+ JSXOpeningElement: ['name', 'typeParameters', 'attributes'],
+ JSXClosingFragment: [],
+ JSXOpeningFragment: [],
+ JSXSpreadChild: ['expression'],
// Additional Nodes.
BigIntLiteral: [],
diff --git a/packages/parser/tests/fixtures/scope-analysis/import-keyword.ts b/packages/parser/tests/fixtures/scope-analysis/import-keyword.ts
new file mode 100644
index 000000000000..3beea868f04b
--- /dev/null
+++ b/packages/parser/tests/fixtures/scope-analysis/import-keyword.ts
@@ -0,0 +1 @@
+import('test');
diff --git a/packages/parser/tests/fixtures/scope-analysis/typed-jsx-element.tsx b/packages/parser/tests/fixtures/scope-analysis/typed-jsx-element.tsx
new file mode 100644
index 000000000000..29158b30c8dc
--- /dev/null
+++ b/packages/parser/tests/fixtures/scope-analysis/typed-jsx-element.tsx
@@ -0,0 +1 @@
+const a = />;
diff --git a/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap b/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap
index 0644b066632e..8fd73916d216 100644
--- a/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap
@@ -5225,6 +5225,56 @@ Object {
}
`;
+exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/import-keyword.ts 1`] = `
+Object {
+ "$id": 1,
+ "block": Object {
+ "range": Array [
+ 0,
+ 16,
+ ],
+ "type": "Program",
+ },
+ "childScopes": Array [
+ Object {
+ "$id": 0,
+ "block": Object {
+ "range": Array [
+ 0,
+ 16,
+ ],
+ "type": "Program",
+ },
+ "childScopes": Array [],
+ "functionExpressionScope": false,
+ "isStrict": true,
+ "references": Array [],
+ "throughReferences": Array [],
+ "type": "module",
+ "upperScope": Object {
+ "$ref": 1,
+ },
+ "variableMap": Object {},
+ "variableScope": Object {
+ "$ref": 0,
+ },
+ "variables": Array [],
+ },
+ ],
+ "functionExpressionScope": false,
+ "isStrict": false,
+ "references": Array [],
+ "throughReferences": Array [],
+ "type": "global",
+ "upperScope": null,
+ "variableMap": Object {},
+ "variableScope": Object {
+ "$ref": 1,
+ },
+ "variables": Array [],
+}
+`;
+
exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/interface-type.ts 1`] = `
Object {
"$id": 1,
@@ -6822,6 +6872,137 @@ Object {
}
`;
+exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/typed-jsx-element.tsx 1`] = `
+Object {
+ "$id": 3,
+ "block": Object {
+ "range": Array [
+ 0,
+ 39,
+ ],
+ "type": "Program",
+ },
+ "childScopes": Array [
+ Object {
+ "$id": 2,
+ "block": Object {
+ "range": Array [
+ 0,
+ 39,
+ ],
+ "type": "Program",
+ },
+ "childScopes": Array [],
+ "functionExpressionScope": false,
+ "isStrict": true,
+ "references": Array [
+ Object {
+ "$id": 1,
+ "from": Object {
+ "$ref": 2,
+ },
+ "identifier": Object {
+ "name": "a",
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Identifier",
+ },
+ "kind": "w",
+ "resolved": Object {
+ "$ref": 0,
+ },
+ "writeExpr": Object {
+ "range": Array [
+ 10,
+ 37,
+ ],
+ "type": "JSXElement",
+ },
+ },
+ ],
+ "throughReferences": Array [],
+ "type": "module",
+ "upperScope": Object {
+ "$ref": 3,
+ },
+ "variableMap": Object {
+ "a": Object {
+ "$ref": 0,
+ },
+ },
+ "variableScope": Object {
+ "$ref": 2,
+ },
+ "variables": Array [
+ Object {
+ "$id": 0,
+ "defs": Array [
+ Object {
+ "name": Object {
+ "name": "a",
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Identifier",
+ },
+ "node": Object {
+ "range": Array [
+ 6,
+ 37,
+ ],
+ "type": "VariableDeclarator",
+ },
+ "parent": Object {
+ "range": Array [
+ 0,
+ 38,
+ ],
+ "type": "VariableDeclaration",
+ },
+ "type": "Variable",
+ },
+ ],
+ "eslintUsed": undefined,
+ "identifiers": Array [
+ Object {
+ "name": "a",
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "name": "a",
+ "references": Array [
+ Object {
+ "$ref": 1,
+ },
+ ],
+ "scope": Object {
+ "$ref": 2,
+ },
+ },
+ ],
+ },
+ ],
+ "functionExpressionScope": false,
+ "isStrict": false,
+ "references": Array [],
+ "throughReferences": Array [],
+ "type": "global",
+ "upperScope": null,
+ "variableMap": Object {},
+ "variableScope": Object {
+ "$ref": 3,
+ },
+ "variables": Array [],
+}
+`;
+
exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/typeof.ts 1`] = `
Object {
"$id": 4,
@@ -15395,6 +15576,31 @@ Object {
}
`;
+exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/import-keyword.ts 1`] = `
+Object {
+ "$id": 0,
+ "block": Object {
+ "range": Array [
+ 0,
+ 16,
+ ],
+ "type": "Program",
+ },
+ "childScopes": Array [],
+ "functionExpressionScope": false,
+ "isStrict": false,
+ "references": Array [],
+ "throughReferences": Array [],
+ "type": "global",
+ "upperScope": null,
+ "variableMap": Object {},
+ "variableScope": Object {
+ "$ref": 0,
+ },
+ "variables": Array [],
+}
+`;
+
exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/interface-type.ts 1`] = `
Object {
"$id": 0,
@@ -16775,6 +16981,112 @@ Object {
}
`;
+exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/typed-jsx-element.tsx 1`] = `
+Object {
+ "$id": 2,
+ "block": Object {
+ "range": Array [
+ 0,
+ 39,
+ ],
+ "type": "Program",
+ },
+ "childScopes": Array [],
+ "functionExpressionScope": false,
+ "isStrict": false,
+ "references": Array [
+ Object {
+ "$id": 1,
+ "from": Object {
+ "$ref": 2,
+ },
+ "identifier": Object {
+ "name": "a",
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Identifier",
+ },
+ "kind": "w",
+ "resolved": Object {
+ "$ref": 0,
+ },
+ "writeExpr": Object {
+ "range": Array [
+ 10,
+ 37,
+ ],
+ "type": "JSXElement",
+ },
+ },
+ ],
+ "throughReferences": Array [],
+ "type": "global",
+ "upperScope": null,
+ "variableMap": Object {
+ "a": Object {
+ "$ref": 0,
+ },
+ },
+ "variableScope": Object {
+ "$ref": 2,
+ },
+ "variables": Array [
+ Object {
+ "$id": 0,
+ "defs": Array [
+ Object {
+ "name": Object {
+ "name": "a",
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Identifier",
+ },
+ "node": Object {
+ "range": Array [
+ 6,
+ 37,
+ ],
+ "type": "VariableDeclarator",
+ },
+ "parent": Object {
+ "range": Array [
+ 0,
+ 38,
+ ],
+ "type": "VariableDeclaration",
+ },
+ "type": "Variable",
+ },
+ ],
+ "eslintUsed": undefined,
+ "identifiers": Array [
+ Object {
+ "name": "a",
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "name": "a",
+ "references": Array [
+ Object {
+ "$ref": 1,
+ },
+ ],
+ "scope": Object {
+ "$ref": 2,
+ },
+ },
+ ],
+}
+`;
+
exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/typeof.ts 1`] = `
Object {
"$id": 3,
diff --git a/packages/parser/tests/lib/scope-analysis.ts b/packages/parser/tests/lib/scope-analysis.ts
index 8eec626225f1..b8eafccc63e9 100644
--- a/packages/parser/tests/lib/scope-analysis.ts
+++ b/packages/parser/tests/lib/scope-analysis.ts
@@ -159,7 +159,9 @@ describe('TypeScript scope analysis', () => {
range: true,
tokens: true,
sourceType: 'module',
- ecmaFeatures: {}
+ ecmaFeatures: {
+ jsx: path.extname(filePath) === '.tsx'
+ }
});
const { globalScope } = scopeManager;
@@ -191,7 +193,9 @@ describe('TypeScript scope analysis', () => {
range: true,
tokens: true,
sourceType: 'script',
- ecmaFeatures: {}
+ ecmaFeatures: {
+ jsx: path.extname(filePath) === '.tsx'
+ }
});
const { globalScope } = scopeManager;
diff --git a/packages/parser/tests/lib/visitor-keys.ts b/packages/parser/tests/lib/visitor-keys.ts
new file mode 100644
index 000000000000..00fcde2a005e
--- /dev/null
+++ b/packages/parser/tests/lib/visitor-keys.ts
@@ -0,0 +1,28 @@
+import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
+import { visitorKeys } from '../../src/visitor-keys';
+
+//------------------------------------------------------------------------------
+// Setup
+//------------------------------------------------------------------------------
+
+const astTypes = Object.keys(AST_NODE_TYPES);
+astTypes.push('TSEmptyBodyFunctionExpression'); // node created by parser.ts
+
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
+describe('visitor-keys', () => {
+ for (const type of astTypes) {
+ it(`type ${type} should be present in visitor-keys`, () => {
+ expect(visitorKeys).toHaveProperty(type);
+ });
+ }
+
+ it('check if there is no deprecated TS nodes', () => {
+ const TSTypes = Object.keys(visitorKeys).filter(type =>
+ type.startsWith('TS')
+ );
+ expect(astTypes).toEqual(expect.arrayContaining(TSTypes));
+ });
+});
diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json
index a8490f513a68..3d112005adce 100644
--- a/packages/typescript-estree/package.json
+++ b/packages/typescript-estree/package.json
@@ -3,6 +3,7 @@
"version": "1.1.0",
"description": "A parser that converts TypeScript source code into an ESTree compatible form",
"main": "dist/parser.js",
+ "types": "dist/parser.d.ts",
"files": [
"dist",
"README.md",
From bdf880bc2c7817852e542fb926a7fa6510c2db69 Mon Sep 17 00:00:00 2001
From: Adam Fields
Date: Sun, 27 Jan 2019 12:12:45 -0500
Subject: [PATCH 42/88] chore: update peer dependencies and node engines (#151)
---
packages/eslint-plugin-tslint/package.json | 3 ++-
packages/eslint-plugin/package.json | 4 ++--
packages/parser/package.json | 4 ++--
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json
index fbe9ea5521e0..d8aeedf6ef0e 100644
--- a/packages/eslint-plugin-tslint/package.json
+++ b/packages/eslint-plugin-tslint/package.json
@@ -11,7 +11,7 @@
"tslint"
],
"engines": {
- "node": ">=6"
+ "node": "^6.14.0 || ^8.10.0 || >=9.10.0"
},
"repository": "typescript-eslint/typescript-eslint",
"bugs": {
@@ -28,6 +28,7 @@
"lodash.memoize": "^4.1.2"
},
"peerDependencies": {
+ "eslint": "^5.0.0",
"tslint": "^5.0.0"
},
"devDependencies": {
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index 7cd6f21b1ab3..7d414aa3576d 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -9,7 +9,7 @@
"typescript"
],
"engines": {
- "node": ">=6"
+ "node": "^6.14.0 || ^8.10.0 || >=9.10.0"
},
"repository": "typescript-eslint/typescript-eslint",
"bugs": {
@@ -32,7 +32,7 @@
"eslint-docs": "^0.2.6"
},
"peerDependencies": {
- "eslint": ">=4.13.1 < 6",
+ "eslint": "^5.0.0",
"typescript": "~3.2.1"
}
}
diff --git a/packages/parser/package.json b/packages/parser/package.json
index 23fe47afce3f..2ba2e642ebd9 100644
--- a/packages/parser/package.json
+++ b/packages/parser/package.json
@@ -9,7 +9,7 @@
"LICENSE"
],
"engines": {
- "node": ">=6.14.0"
+ "node": "^6.14.0 || ^8.10.0 || >=9.10.0"
},
"repository": "typescript-eslint/typescript-eslint",
"bugs": {
@@ -32,7 +32,7 @@
"test": "jest --coverage"
},
"peerDependencies": {
- "eslint": ">=4.19.1",
+ "eslint": "^5.0.0",
"typescript": "*"
},
"dependencies": {
From 4954ed2c476bf9654ffe020b587fd6691a985d01 Mon Sep 17 00:00:00 2001
From: Armano
Date: Sun, 27 Jan 2019 18:18:11 +0100
Subject: [PATCH 43/88] refactor(ts-estree): simplify methods location
calculation (#152)
---
packages/typescript-estree/src/convert.ts | 66 ++++++--------------
packages/typescript-estree/src/node-utils.ts | 56 +++++++----------
2 files changed, 39 insertions(+), 83 deletions(-)
diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts
index ff365b187c7e..bc9e209f23ed 100644
--- a/packages/typescript-estree/src/convert.ts
+++ b/packages/typescript-estree/src/convert.ts
@@ -23,10 +23,10 @@ import {
isComma,
getBinaryExpressionType,
isOptional,
- findFirstMatchingToken,
unescapeStringLiteralText,
getDeclarationKind,
- getLastModifier
+ getLastModifier,
+ getLineAndCharacterFor
} from './node-utils';
import { AST_NODE_TYPES } from './ast-node-types';
import { ESTreeNode } from './temp-types-based-on-js-source';
@@ -858,38 +858,19 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.MethodDeclaration: {
- const openingParen = findFirstMatchingToken(
- node.name,
- ast,
- (token: any) => {
- if (!token || !token.kind) {
- return false;
- }
- return getTextForTokenKind(token.kind) === '(';
- },
- ast
- );
-
- const methodLoc = ast.getLineAndCharacterOfPosition(
- (openingParen as any).getStart(ast)
- ),
- nodeIsMethod = node.kind === SyntaxKind.MethodDeclaration,
- method: ESTreeNode = {
- type: AST_NODE_TYPES.FunctionExpression,
- id: null,
- generator: !!node.asteriskToken,
- expression: false, // ESTreeNode as ESTreeNode here
- async: hasModifier(SyntaxKind.AsyncKeyword, node),
- body: convertChild(node.body),
- range: [node.parameters.pos - 1, result.range[1]],
- loc: {
- start: {
- line: methodLoc.line + 1,
- column: methodLoc.character
- },
- end: result.loc.end
- }
- } as any;
+ const method: ESTreeNode = {
+ type: AST_NODE_TYPES.FunctionExpression,
+ id: null,
+ generator: !!node.asteriskToken,
+ expression: false, // ESTreeNode as ESTreeNode here
+ async: hasModifier(SyntaxKind.AsyncKeyword, node),
+ body: convertChild(node.body),
+ range: [node.parameters.pos - 1, result.range[1]],
+ loc: {
+ start: getLineAndCharacterFor(node.parameters.pos - 1, ast),
+ end: result.loc.end
+ }
+ } as any;
if (node.type) {
(method as any).returnType = convertTypeAnnotation(node.type);
@@ -903,7 +884,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
key: convertChild(node.name),
value: method,
computed: isComputedProperty(node.name),
- method: nodeIsMethod,
+ method: node.kind === SyntaxKind.MethodDeclaration,
shorthand: false,
kind: 'init'
});
@@ -992,10 +973,6 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
constructorToken.end
];
- const constructorLoc = ast.getLineAndCharacterOfPosition(
- node.parameters.pos - 1
- );
-
const constructor: ESTreeNode = {
type: AST_NODE_TYPES.FunctionExpression,
id: null,
@@ -1006,10 +983,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
body: convertChild(node.body),
range: [node.parameters.pos - 1, result.range[1]],
loc: {
- start: {
- line: constructorLoc.line + 1,
- column: constructorLoc.character
- },
+ start: getLineAndCharacterFor(node.parameters.pos - 1, ast),
end: result.loc.end
}
} as any;
@@ -1906,16 +1880,12 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
break;
case SyntaxKind.JsxExpression: {
- const eloc = ast.getLineAndCharacterOfPosition(result.range[0] + 1);
const expression = node.expression
? convertChild(node.expression)
: {
type: AST_NODE_TYPES.JSXEmptyExpression,
loc: {
- start: {
- line: eloc.line + 1,
- column: eloc.character
- },
+ start: getLineAndCharacterFor(result.range[0] + 1, ast),
end: {
line: result.loc.end.line,
column: result.loc.end.column - 1
diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts
index c844cf7ed20d..d79353f755e6 100644
--- a/packages/typescript-estree/src/node-utils.ts
+++ b/packages/typescript-estree/src/node-utils.ts
@@ -9,7 +9,8 @@ import unescape from 'lodash.unescape';
import {
ESTreeNodeLoc,
ESTreeNode,
- ESTreeToken
+ ESTreeToken,
+ LineAndColumnData
} from './temp-types-based-on-js-source';
import { AST_NODE_TYPES } from './ast-node-types';
@@ -219,6 +220,23 @@ export function getBinaryExpressionType(
return AST_NODE_TYPES.BinaryExpression;
}
+/**
+ * Returns line and column data for the given positions,
+ * @param pos position to check
+ * @param ast the AST object
+ * @returns line and column
+ */
+export function getLineAndCharacterFor(
+ pos: number,
+ ast: ts.SourceFile
+): LineAndColumnData {
+ const loc = ast.getLineAndCharacterOfPosition(pos);
+ return {
+ line: loc.line + 1,
+ column: loc.character
+ };
+}
+
/**
* Returns line and column data for the given start and end positions,
* for the given AST
@@ -232,18 +250,9 @@ export function getLocFor(
end: number,
ast: ts.SourceFile
): ESTreeNodeLoc {
- const startLoc = ast.getLineAndCharacterOfPosition(start),
- endLoc = ast.getLineAndCharacterOfPosition(end);
-
return {
- start: {
- line: startLoc.line + 1,
- column: startLoc.character
- },
- end: {
- line: endLoc.line + 1,
- column: endLoc.character
- }
+ start: getLineAndCharacterFor(start, ast),
+ end: getLineAndCharacterFor(end, ast)
};
}
@@ -389,29 +398,6 @@ export function findNextToken(
}
}
-/**
- * Find the first matching token based on the given predicate function.
- * @param {ts.Node} previousToken The previous ts.Token
- * @param {ts.Node} parent The parent ts.Node
- * @param {Function} predicate The predicate function to apply to each checked token
- * @param {ts.SourceFile} ast The TS AST
- * @returns {ts.Node|undefined} a matching ts.Token
- */
-export function findFirstMatchingToken(
- previousToken: ts.Node | undefined,
- parent: ts.Node,
- predicate: (node: ts.Node) => boolean,
- ast: ts.SourceFile
-): ts.Node | undefined {
- while (previousToken) {
- if (predicate(previousToken)) {
- return previousToken;
- }
- previousToken = findNextToken(previousToken, parent, ast);
- }
- return undefined;
-}
-
/**
* Find the first matching ancestor based on the given predicate function.
* @param {ts.Node} node The current ts.Node
From e291ec30240b109c19111d1eedb81440f3fa2670 Mon Sep 17 00:00:00 2001
From: Armano
Date: Sun, 27 Jan 2019 18:25:35 +0100
Subject: [PATCH 44/88] refactor(ts-estree): remove dead legacy code (#153)
---
packages/typescript-estree/src/convert.ts | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)
diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts
index bc9e209f23ed..9a7adebc8e2e 100644
--- a/packages/typescript-estree/src/convert.ts
+++ b/packages/typescript-estree/src/convert.ts
@@ -796,21 +796,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
}
case SyntaxKind.ComputedPropertyName:
- if (parent!.kind === SyntaxKind.ObjectLiteralExpression) {
- // TODO: ComputedPropertyName has no name field
- Object.assign(result, {
- type: AST_NODE_TYPES.Property,
- key: convertChild((node as any).name),
- value: convertChild((node as any).name),
- computed: false,
- method: false,
- shorthand: true,
- kind: 'init'
- });
- } else {
- return convertChild(node.expression);
- }
- break;
+ return convertChild(node.expression);
case SyntaxKind.PropertyDeclaration: {
const isAbstract = hasModifier(SyntaxKind.AbstractKeyword, node);
From 5017c115f232b42285c61ae53dcf531d66a9c4b5 Mon Sep 17 00:00:00 2001
From: ikeryo1182
Date: Tue, 29 Jan 2019 07:42:39 +0700
Subject: [PATCH 45/88] chore: upgrade husky and lint-staged (#144)
---
.huskyrc | 8 +++
.lintstagedrc | 6 ++
package.json | 14 +---
yarn.lock | 196 ++++++++++++++++++++++++++++++++++++++++++--------
4 files changed, 183 insertions(+), 41 deletions(-)
create mode 100644 .huskyrc
create mode 100644 .lintstagedrc
diff --git a/.huskyrc b/.huskyrc
new file mode 100644
index 000000000000..a3f3f7002ed4
--- /dev/null
+++ b/.huskyrc
@@ -0,0 +1,8 @@
+{
+ "hooks": {
+ "pre-commit": [
+ "yarn test && lint-staged"
+ ],
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
+ }
+}
diff --git a/.lintstagedrc b/.lintstagedrc
new file mode 100644
index 000000000000..889b734ac28f
--- /dev/null
+++ b/.lintstagedrc
@@ -0,0 +1,6 @@
+{
+ "*.{ts,js,json,md}": [
+ "prettier --write",
+ "git add"
+ ]
+}
diff --git a/package.json b/package.json
index c7a27e9a643d..18059f7381ed 100644
--- a/package.json
+++ b/package.json
@@ -21,22 +21,14 @@
"test": "lerna run test --parallel",
"build": "lerna run build",
"clean": "lerna clean && lerna run clean",
- "precommit": "yarn test && lint-staged",
"lint": "eslint . --ext .js,.ts",
"lint-fix": "eslint . --ext .js,.ts --fix",
"cz": "git-cz",
- "commitmsg": "commitlint -E GIT_PARAMS",
"check-format": "prettier --list-different \"./**/*.{ts,js,json,md}\"",
"format": "prettier --write \"./**/*.{ts,js,json,md}\"",
"integration-tests": "docker-compose -f tests/integration/docker-compose.yml up",
"kill-integration-test-containers": "docker-compose -f tests/integration/docker-compose.yml down -v --rmi local"
},
- "lint-staged": {
- "*.{ts,js,json,md}": [
- "prettier --write",
- "git add"
- ]
- },
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
@@ -65,13 +57,13 @@
"@types/semver": "^5.5.0",
"cz-conventional-changelog": "2.1.0",
"eslint": "^5.12.1",
- "eslint-plugin-jest": "^22.1.3",
"eslint-plugin-eslint-plugin": "^2.0.1",
+ "eslint-plugin-jest": "^22.1.3",
"glob": "7.1.2",
- "husky": "0.14.3",
+ "husky": "^1.3.1",
"jest": "23.6.0",
"lerna": "^3.10.5",
- "lint-staged": "7.3.0",
+ "lint-staged": "8.1.0",
"lodash.isplainobject": "4.0.6",
"prettier": "^1.14.3",
"rimraf": "^2.6.3",
diff --git a/yarn.lock b/yarn.lock
index e2d917cdc557..b6a6d614dfc0 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -163,6 +163,20 @@
babel-runtime "6.26.0"
execa "0.9.0"
+"@iamstarkov/listr-update-renderer@0.4.1":
+ version "0.4.1"
+ resolved "https://registry.yarnpkg.com/@iamstarkov/listr-update-renderer/-/listr-update-renderer-0.4.1.tgz#d7c48092a2dcf90fd672b6c8b458649cb350c77e"
+ integrity sha512-IJyxQWsYDEkf8C8QthBn5N8tIUR9V9je6j3sMIpAkonaadjbvxmRC6RAhpa3RKxndhNnU2M6iNbtJwd7usQYIA==
+ dependencies:
+ chalk "^1.1.3"
+ cli-truncate "^0.2.1"
+ elegant-spinner "^1.0.1"
+ figures "^1.7.0"
+ indent-string "^3.0.0"
+ log-symbols "^1.0.2"
+ log-update "^2.3.0"
+ strip-ansi "^3.0.1"
+
"@lerna/add@3.10.5":
version "3.10.5"
resolved "https://registry.yarnpkg.com/@lerna/add/-/add-3.10.5.tgz#10dcd1069eee18a84432f826a38d6791af8a2fef"
@@ -1618,6 +1632,11 @@ ci-info@^1.5.0:
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497"
integrity sha512-vsGdkwSCDpWmP80ncATX7iea5DWQemg1UgCW5J8tqjU3lYw4FBYuj89J0CTVomA7BEfvSZd84GmHko+MxFQU2A==
+ci-info@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46"
+ integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==
+
circular-json@^0.3.1:
version "0.3.3"
resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66"
@@ -1919,6 +1938,15 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
+cosmiconfig@5.0.6:
+ version "5.0.6"
+ resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.6.tgz#dca6cf680a0bd03589aff684700858c81abeeb39"
+ integrity sha512-6DWfizHriCrFWURP1/qyhsiFvYdlJzbCzmtFWh744+KyWsJo5+kPzUZZaMRSSItoYc0pxFX7gEO7ZC1/gN/7AQ==
+ dependencies:
+ is-directory "^0.3.1"
+ js-yaml "^3.9.0"
+ parse-json "^4.0.0"
+
cosmiconfig@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-4.0.0.tgz#760391549580bbd2df1e562bc177b13c290972dc"
@@ -1929,7 +1957,7 @@ cosmiconfig@^4.0.0:
parse-json "^4.0.0"
require-from-string "^2.0.1"
-cosmiconfig@^5.0.2:
+cosmiconfig@^5.0.2, cosmiconfig@^5.0.7:
version "5.0.7"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.7.tgz#39826b292ee0d78eda137dfa3173bd1c21a43b04"
integrity sha512-PcLqxTKiDmNT6pSpy4N6KtuPwb53W+2tzNvwOZw0WH9N6O0vLIBq0x8aj8Oj75ere4YcGi48bDFCL+3fRJdlNA==
@@ -2136,6 +2164,18 @@ define-property@^2.0.2:
is-descriptor "^1.0.2"
isobject "^3.0.1"
+del@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/del/-/del-3.0.0.tgz#53ecf699ffcbcb39637691ab13baf160819766e5"
+ integrity sha1-U+z2mf/LyzljdpGrE7rxYIGXZuU=
+ dependencies:
+ globby "^6.1.0"
+ is-path-cwd "^1.0.0"
+ is-path-in-cwd "^1.0.0"
+ p-map "^1.1.1"
+ pify "^3.0.0"
+ rimraf "^2.2.8"
+
delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
@@ -2304,7 +2344,7 @@ es6-promisify@^5.0.0:
dependencies:
es6-promise "^4.0.3"
-escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
+escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.4, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
@@ -2497,7 +2537,7 @@ exec-sh@^0.2.0:
dependencies:
merge "^1.2.0"
-execa@0.9.0, execa@^0.9.0:
+execa@0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.9.0.tgz#adb7ce62cf985071f60580deb4a88b9e34712d01"
integrity sha512-BbUMBiX4hqiHZUA5+JujIjNb6TyAlp2D5KLheMjMluwOuzcnylDL4AxZYLLn1n2AGB49eSWwyKvvEQoRpnAtmA==
@@ -2895,6 +2935,15 @@ functional-red-black-tree@^1.0.1:
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=
+g-status@^2.0.2:
+ version "2.0.2"
+ resolved "https://registry.yarnpkg.com/g-status/-/g-status-2.0.2.tgz#270fd32119e8fc9496f066fe5fe88e0a6bc78b97"
+ integrity sha512-kQoE9qH+T1AHKgSSD0Hkv98bobE90ILQcXAF4wvGgsr7uFqNvwmh8j+Lq3l0RVt3E3HjSbv2B9biEGcEtpHLCA==
+ dependencies:
+ arrify "^1.0.1"
+ matcher "^1.0.0"
+ simple-git "^1.85.0"
+
gauge@~2.7.3:
version "2.7.4"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
@@ -2964,6 +3013,11 @@ get-stdin@^4.0.1:
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=
+get-stdin@^6.0.0:
+ version "6.0.0"
+ resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
+ integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
+
get-stream@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"
@@ -3102,6 +3156,17 @@ globals@^9.18.0:
resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a"
integrity sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==
+globby@^6.1.0:
+ version "6.1.0"
+ resolved "https://registry.yarnpkg.com/globby/-/globby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c"
+ integrity sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=
+ dependencies:
+ array-union "^1.0.1"
+ glob "^7.0.3"
+ object-assign "^4.0.1"
+ pify "^2.0.0"
+ pinkie-promise "^2.0.0"
+
globby@^8.0.1:
version "8.0.2"
resolved "https://registry.yarnpkg.com/globby/-/globby-8.0.2.tgz#5697619ccd95c5275dbb2d6faa42087c1a941d8d"
@@ -3271,14 +3336,21 @@ humanize-ms@^1.2.1:
dependencies:
ms "^2.0.0"
-husky@0.14.3:
- version "0.14.3"
- resolved "https://registry.yarnpkg.com/husky/-/husky-0.14.3.tgz#c69ed74e2d2779769a17ba8399b54ce0b63c12c3"
- integrity sha512-e21wivqHpstpoiWA/Yi8eFti8E+sQDSS53cpJsPptPs295QTOQR0ZwnHo2TXy1XOpZFD9rPOd3NpmqTK6uMLJA==
+husky@^1.3.1:
+ version "1.3.1"
+ resolved "https://registry.yarnpkg.com/husky/-/husky-1.3.1.tgz#26823e399300388ca2afff11cfa8a86b0033fae0"
+ integrity sha512-86U6sVVVf4b5NYSZ0yvv88dRgBSSXXmHaiq5pP4KDj5JVzdwKgBjEtUPOm8hcoytezFwbU+7gotXNhpHdystlg==
dependencies:
- is-ci "^1.0.10"
- normalize-path "^1.0.0"
- strip-indent "^2.0.0"
+ cosmiconfig "^5.0.7"
+ execa "^1.0.0"
+ find-up "^3.0.0"
+ get-stdin "^6.0.0"
+ is-ci "^2.0.0"
+ pkg-dir "^3.0.0"
+ please-upgrade-node "^3.1.1"
+ read-pkg "^4.0.1"
+ run-node "^1.0.0"
+ slash "^2.0.0"
iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13:
version "0.4.24"
@@ -3471,6 +3543,13 @@ is-ci@^1.0.10:
dependencies:
ci-info "^1.5.0"
+is-ci@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c"
+ integrity sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==
+ dependencies:
+ ci-info "^2.0.0"
+
is-data-descriptor@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56"
@@ -3623,6 +3702,25 @@ is-observable@^1.1.0:
dependencies:
symbol-observable "^1.1.0"
+is-path-cwd@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-1.0.0.tgz#d225ec23132e89edd38fda767472e62e65f1106d"
+ integrity sha1-0iXsIxMuie3Tj9p2dHLmLmXxEG0=
+
+is-path-in-cwd@^1.0.0:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/is-path-in-cwd/-/is-path-in-cwd-1.0.1.tgz#5ac48b345ef675339bd6c7a48a912110b241cf52"
+ integrity sha512-FjV1RTW48E7CWM7eE/J2NJvAEEVektecDBVBE5Hh3nM1Jd0kvhHtX68Pr3xsDf857xt3Y4AkwVULK1Vku62aaQ==
+ dependencies:
+ is-path-inside "^1.0.0"
+
+is-path-inside@^1.0.0:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-1.0.1.tgz#8ef5b7de50437a3fdca6b4e865ef7aa55cb48036"
+ integrity sha1-jvW33lBDej/cprToZe96pVy0gDY=
+ dependencies:
+ path-is-inside "^1.0.1"
+
is-plain-obj@^1.0.0, is-plain-obj@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
@@ -4417,22 +4515,25 @@ libnpmteam@^1.0.1:
get-stream "^4.0.0"
npm-registry-fetch "^3.8.0"
-lint-staged@7.3.0:
- version "7.3.0"
- resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-7.3.0.tgz#90ff33e5ca61ed3dbac35b6f6502dbefdc0db58d"
- integrity sha512-AXk40M9DAiPi7f4tdJggwuKIViUplYtVj1os1MVEteW7qOkU50EOehayCfO9TsoGK24o/EsWb41yrEgfJDDjCw==
+lint-staged@8.1.0:
+ version "8.1.0"
+ resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-8.1.0.tgz#dbc3ae2565366d8f20efb9f9799d076da64863f2"
+ integrity sha512-yfSkyJy7EuVsaoxtUSEhrD81spdJOe/gMTGea3XaV7HyoRhTb9Gdlp6/JppRZERvKSEYXP9bjcmq6CA5oL2lYQ==
dependencies:
+ "@iamstarkov/listr-update-renderer" "0.4.1"
chalk "^2.3.1"
commander "^2.14.1"
- cosmiconfig "^5.0.2"
+ cosmiconfig "5.0.6"
debug "^3.1.0"
dedent "^0.7.0"
- execa "^0.9.0"
+ del "^3.0.0"
+ execa "^1.0.0"
find-parent-dir "^0.3.0"
+ g-status "^2.0.2"
is-glob "^4.0.0"
is-windows "^1.0.2"
jest-validate "^23.5.0"
- listr "^0.14.1"
+ listr "^0.14.2"
lodash "^4.17.5"
log-symbols "^2.2.0"
micromatch "^3.1.8"
@@ -4441,7 +4542,7 @@ lint-staged@7.3.0:
path-is-inside "^1.0.2"
pify "^3.0.0"
please-upgrade-node "^3.0.2"
- staged-git-files "1.1.1"
+ staged-git-files "1.1.2"
string-argv "^0.0.2"
stringify-object "^3.2.2"
@@ -4474,7 +4575,7 @@ listr-verbose-renderer@^0.5.0:
date-fns "^1.27.2"
figures "^2.0.0"
-listr@^0.14.1:
+listr@^0.14.2:
version "0.14.3"
resolved "https://registry.yarnpkg.com/listr/-/listr-0.14.3.tgz#2fea909604e434be464c50bddba0d496928fa586"
integrity sha512-RmAl7su35BFd/xoMamRjpIE4j3v+L28o8CT5YhAXQJm1fD+1l9ngXY8JAQRJ+tFK2i5njvi0iRUKV09vPwA0iA==
@@ -4712,6 +4813,13 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"
+matcher@^1.0.0:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/matcher/-/matcher-1.1.1.tgz#51d8301e138f840982b338b116bb0c09af62c1c2"
+ integrity sha512-+BmqxWIubKTRKNWx/ahnCkk3mG8m7OturVlqq6HiojGJTd5hVYbgZm6WzcYPCoB+KBT4Vd6R7WSRG2OADNaCjg==
+ dependencies:
+ escape-string-regexp "^1.0.4"
+
math-random@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.4.tgz#5dd6943c938548267016d4e34f057583080c514c"
@@ -5107,11 +5215,6 @@ normalize-package-data@^2.0.0, normalize-package-data@^2.3.0, normalize-package-
semver "2 || 3 || 4 || 5"
validate-npm-package-license "^3.0.1"
-normalize-path@^1.0.0:
- version "1.0.0"
- resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-1.0.0.tgz#32d0e472f91ff345701c15a8311018d3b0a90379"
- integrity sha1-MtDkcvkf80VwHBWoMRAY07CpA3k=
-
normalize-path@^2.0.1, normalize-path@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9"
@@ -5633,7 +5736,14 @@ pkg-dir@^2.0.0:
dependencies:
find-up "^2.1.0"
-please-upgrade-node@^3.0.2:
+pkg-dir@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-3.0.0.tgz#2749020f239ed990881b1f71210d51eb6523bea3"
+ integrity sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==
+ dependencies:
+ find-up "^3.0.0"
+
+please-upgrade-node@^3.0.2, please-upgrade-node@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.1.1.tgz#ed320051dfcc5024fae696712c8288993595e8ac"
integrity sha512-KY1uHnQ2NlQHqIJQpnh/i54rKkuxCEBx+voJIS/Mvb+L2iYd2NMotwduhKTMjfC1uKoX3VXOxLjIYG66dfJTVQ==
@@ -5884,6 +5994,15 @@ read-pkg@^3.0.0:
normalize-package-data "^2.3.2"
path-type "^3.0.0"
+read-pkg@^4.0.1:
+ version "4.0.1"
+ resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-4.0.1.tgz#963625378f3e1c4d48c85872b5a6ec7d5d093237"
+ integrity sha1-ljYlN48+HE1IyFhytabsfV0JMjc=
+ dependencies:
+ normalize-package-data "^2.3.2"
+ parse-json "^4.0.0"
+ pify "^3.0.0"
+
read@1, read@~1.0.1:
version "1.0.7"
resolved "https://registry.yarnpkg.com/read/-/read-1.0.7.tgz#b3da19bd052431a97671d44a42634adf710b40c4"
@@ -6128,7 +6247,7 @@ right-pad@^1.0.1:
resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0"
integrity sha1-jKCMLLtbVedNr6lr9/0aJ9VoyNA=
-rimraf@2, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@^2.6.3, rimraf@~2.6.2:
+rimraf@2, rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@^2.6.3, rimraf@~2.6.2:
version "2.6.3"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==
@@ -6147,6 +6266,11 @@ run-async@^2.2.0:
dependencies:
is-promise "^2.1.0"
+run-node@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/run-node/-/run-node-1.0.0.tgz#46b50b946a2aa2d4947ae1d886e9856fd9cabe5e"
+ integrity sha512-kc120TBlQ3mih1LSzdAJXo4xn/GWS2ec0l3S+syHDXP9uRr0JAT8Qd3mdMuyjqCzeZktgP3try92cEgf9Nks8A==
+
run-queue@^1.0.0, run-queue@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/run-queue/-/run-queue-1.0.3.tgz#e848396f057d223f24386924618e25694161ec47"
@@ -6266,6 +6390,13 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
+simple-git@^1.85.0:
+ version "1.107.0"
+ resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-1.107.0.tgz#12cffaf261c14d6f450f7fdb86c21ccee968b383"
+ integrity sha512-t4OK1JRlp4ayKRfcW6owrWcRVLyHRUlhGd0uN6ZZTqfDq8a5XpcUdOKiGRNobHEuMtNqzp0vcJNvhYWwh5PsQA==
+ dependencies:
+ debug "^4.0.1"
+
sisteransi@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-0.1.1.tgz#5431447d5f7d1675aac667ccd0b865a4994cb3ce"
@@ -6276,6 +6407,11 @@ slash@^1.0.0:
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
integrity sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU=
+slash@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44"
+ integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==
+
slice-ansi@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35"
@@ -6473,10 +6609,10 @@ stack-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-1.0.2.tgz#33eba3897788558bebfc2db059dc158ec36cebb8"
integrity sha512-MTX+MeG5U994cazkjd/9KNAapsHnibjMLnfXodlkXw76JEea0UiNzrqidzo1emMwk7w5Qhc9jd4Bn9TBb1MFwA==
-staged-git-files@1.1.1:
- version "1.1.1"
- resolved "https://registry.yarnpkg.com/staged-git-files/-/staged-git-files-1.1.1.tgz#37c2218ef0d6d26178b1310719309a16a59f8f7b"
- integrity sha512-H89UNKr1rQJvI1c/PIR3kiAMBV23yvR7LItZiV74HWZwzt7f3YHuujJ9nJZlt58WlFox7XQsOahexwk7nTe69A==
+staged-git-files@1.1.2:
+ version "1.1.2"
+ resolved "https://registry.yarnpkg.com/staged-git-files/-/staged-git-files-1.1.2.tgz#4326d33886dc9ecfa29a6193bf511ba90a46454b"
+ integrity sha512-0Eyrk6uXW6tg9PYkhi/V/J4zHp33aNyi2hOCmhFLqLTIhbgqWn5jlSzI+IU0VqrZq6+DbHcabQl/WP6P3BG0QA==
static-extend@^0.1.1:
version "0.1.2"
From aacf5b05c7f0d802bbc28222d7c95141fa0ff86c Mon Sep 17 00:00:00 2001
From: James Henry
Date: Mon, 28 Jan 2019 21:25:44 -0500
Subject: [PATCH 46/88] perf(ts-estree): don't create Program in parse() (#148)
---
packages/typescript-estree/src/parser.ts | 347 ++++++++++--------
.../tests/lib/__snapshots__/parse.ts.snap | 82 ++++-
packages/typescript-estree/tests/lib/parse.ts | 7 +-
.../tests/lib/semanticInfo.ts | 18 +
.../tests/lib/warn-on-unsupported-ts.ts | 22 ++
5 files changed, 324 insertions(+), 152 deletions(-)
create mode 100644 packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts
diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts
index ff2784aa9963..225899a106f9 100644
--- a/packages/typescript-estree/src/parser.ts
+++ b/packages/typescript-estree/src/parser.ts
@@ -36,7 +36,10 @@ let extra: Extra;
let warnedAboutTSVersion = false;
/**
- * Compute the filename based on the parser options
+ * Compute the filename based on the parser options.
+ *
+ * Even if jsx option is set in typescript compiler, filename still has to
+ * contain .tsx file extension.
*
* @param options Parser options
*/
@@ -106,8 +109,6 @@ function getASTAndDefaultProject(code: string, options: ParserOptions) {
* @returns {{ast: ts.SourceFile, program: ts.Program}} Returns a new source file and program corresponding to the linted code
*/
function createNewProgram(code: string) {
- // Even if jsx option is set in typescript compiler, filename still has to
- // contain .tsx file extension
const FILENAME = getFileName(extra);
const compilerHost = {
@@ -178,6 +179,98 @@ function getProgramAndAST(
);
}
+function applyParserOptionsToExtra(options: ParserOptions): void {
+ /**
+ * Track range information in the AST
+ */
+ extra.range = typeof options.range === 'boolean' && options.range;
+ extra.loc = typeof options.loc === 'boolean' && options.loc;
+ /**
+ * Track tokens in the AST
+ */
+ if (typeof options.tokens === 'boolean' && options.tokens) {
+ extra.tokens = [];
+ }
+ /**
+ * Track comments in the AST
+ */
+ if (typeof options.comment === 'boolean' && options.comment) {
+ extra.comment = true;
+ extra.comments = [];
+ }
+ /**
+ * Enable JSX - note the applicable file extension is still required
+ */
+ if (typeof options.jsx === 'boolean' && options.jsx) {
+ extra.jsx = true;
+ }
+ /**
+ * The JSX AST changed the node type for string literals
+ * inside a JSX Element from `Literal` to `JSXText`.
+ *
+ * When value is `true`, these nodes will be parsed as type `JSXText`.
+ * When value is `false`, these nodes will be parsed as type `Literal`.
+ */
+ if (typeof options.useJSXTextNode === 'boolean' && options.useJSXTextNode) {
+ extra.useJSXTextNode = true;
+ }
+ /**
+ * Allow the user to cause the parser to error if it encounters an unknown AST Node Type
+ * (used in testing)
+ */
+ if (
+ typeof options.errorOnUnknownASTType === 'boolean' &&
+ options.errorOnUnknownASTType
+ ) {
+ extra.errorOnUnknownASTType = true;
+ }
+ /**
+ * Allow the user to override the function used for logging
+ */
+ if (typeof options.loggerFn === 'function') {
+ extra.log = options.loggerFn;
+ } else if (options.loggerFn === false) {
+ extra.log = Function.prototype;
+ }
+
+ if (typeof options.project === 'string') {
+ extra.projects = [options.project];
+ } else if (
+ Array.isArray(options.project) &&
+ options.project.every(projectPath => typeof projectPath === 'string')
+ ) {
+ extra.projects = options.project;
+ }
+
+ if (typeof options.tsconfigRootDir === 'string') {
+ extra.tsconfigRootDir = options.tsconfigRootDir;
+ }
+
+ if (
+ Array.isArray(options.extraFileExtensions) &&
+ options.extraFileExtensions.every(ext => typeof ext === 'string')
+ ) {
+ extra.extraFileExtensions = options.extraFileExtensions;
+ }
+}
+
+function warnAboutTSVersion(): void {
+ if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) {
+ const border = '=============';
+ const versionWarning = [
+ border,
+ 'WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.',
+ 'You may find that it works just fine, or you may not.',
+ `SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`,
+ `YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`,
+ 'Please only submit bug reports when using the officially supported version.',
+ border
+ ];
+ extra.log(versionWarning.join('\n\n'));
+ warnedAboutTSVersion = true;
+ }
+}
+
//------------------------------------------------------------------------------
// Parser
//------------------------------------------------------------------------------
@@ -187,143 +280,118 @@ type AST = Program &
(T['tokens'] extends true ? { tokens: ESTreeToken[] } : {}) &
(T['comment'] extends true ? { comments: ESTreeComment[] } : {});
-/**
- * Parses the given source code to produce a valid AST
- * @param {string} code TypeScript code
- * @param {boolean} shouldGenerateServices Flag determining whether to generate ast maps and program or not
- * @param {ParserOptions} options configuration object for the parser
- * @returns {Object} the AST
- */
-function generateAST(
+interface ParseAndGenerateServicesResult {
+ ast: AST;
+ services: {
+ program: ts.Program | undefined;
+ esTreeNodeToTSNodeMap: WeakMap | undefined;
+ tsNodeToESTreeNodeMap: WeakMap | undefined;
+ };
+}
+
+//------------------------------------------------------------------------------
+// Public
+//------------------------------------------------------------------------------
+
+export const version: string = packageJSON.version;
+
+export function parse(
code: string,
- options: T = {} as T,
- shouldGenerateServices = false
-): {
- estree: AST;
- program: typeof shouldGenerateServices extends true
- ? ts.Program
- : (ts.Program | undefined);
- astMaps: typeof shouldGenerateServices extends true
- ? {
- esTreeNodeToTSNodeMap: WeakMap;
- tsNodeToESTreeNodeMap: WeakMap;
- }
- : {
- esTreeNodeToTSNodeMap?: WeakMap;
- tsNodeToESTreeNodeMap?: WeakMap;
- };
-} {
+ options?: T
+): AST {
+ /**
+ * Reset the parse configuration
+ */
+ resetExtra();
+ /**
+ * Ensure users do not attempt to use parse() when they need parseAndGenerateServices()
+ */
+ if (options && options.errorOnTypeScriptSyntacticAndSemanticIssues) {
+ throw new Error(
+ `"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()`
+ );
+ }
+ /**
+ * Ensure the source code is a string, and store a reference to it
+ */
if (typeof code !== 'string' && !((code as any) instanceof String)) {
code = String(code);
}
+ extra.code = code;
+ /**
+ * Apply the given parser options
+ */
+ if (typeof options !== 'undefined') {
+ applyParserOptionsToExtra(options);
+ }
+ /**
+ * Warn if the user is using an unsupported version of TypeScript
+ */
+ warnAboutTSVersion();
+ /**
+ * Create a ts.SourceFile directly, no ts.Program is needed for a simple
+ * parse
+ */
+ const ast = ts.createSourceFile(
+ getFileName(extra),
+ code,
+ ts.ScriptTarget.Latest,
+ /* setParentNodes */ true
+ );
+ /**
+ * Convert the TypeScript AST to an ESTree-compatible one
+ */
+ const { estree } = convert(ast, extra, false);
+ return estree;
+}
+export function parseAndGenerateServices<
+ T extends ParserOptions = ParserOptions
+>(code: string, options: T): ParseAndGenerateServicesResult {
+ /**
+ * Reset the parse configuration
+ */
resetExtra();
-
+ /**
+ * Ensure the source code is a string, and store a reference to it
+ */
+ if (typeof code !== 'string' && !((code as any) instanceof String)) {
+ code = String(code);
+ }
+ extra.code = code;
+ /**
+ * Apply the given parser options
+ */
if (typeof options !== 'undefined') {
- extra.range = typeof options.range === 'boolean' && options.range;
- extra.loc = typeof options.loc === 'boolean' && options.loc;
-
- if (typeof options.tokens === 'boolean' && options.tokens) {
- extra.tokens = [];
- }
-
- if (typeof options.comment === 'boolean' && options.comment) {
- extra.comment = true;
- extra.comments = [];
- }
-
- if (typeof options.jsx === 'boolean' && options.jsx) {
- extra.jsx = true;
- }
-
- /**
- * Allow the user to cause the parser to error if it encounters an unknown AST Node Type
- * (used in testing).
- */
- if (
- typeof options.errorOnUnknownASTType === 'boolean' &&
- options.errorOnUnknownASTType
- ) {
- extra.errorOnUnknownASTType = true;
- }
-
- /**
- * Retrieve semantic and syntactic diagnostics from the underlying TypeScript Program
- * and turn them into parse errors
- */
+ applyParserOptionsToExtra(options);
if (
- shouldGenerateServices &&
typeof options.errorOnTypeScriptSyntacticAndSemanticIssues ===
'boolean' &&
options.errorOnTypeScriptSyntacticAndSemanticIssues
) {
extra.errorOnTypeScriptSyntacticAndSemanticIssues = true;
}
-
- if (typeof options.useJSXTextNode === 'boolean' && options.useJSXTextNode) {
- extra.useJSXTextNode = true;
- }
-
- /**
- * Allow the user to override the function used for logging
- */
- if (typeof options.loggerFn === 'function') {
- extra.log = options.loggerFn;
- } else if (options.loggerFn === false) {
- extra.log = Function.prototype;
- }
-
- if (typeof options.project === 'string') {
- extra.projects = [options.project];
- } else if (
- Array.isArray(options.project) &&
- options.project.every(projectPath => typeof projectPath === 'string')
- ) {
- extra.projects = options.project;
- }
-
- if (typeof options.tsconfigRootDir === 'string') {
- extra.tsconfigRootDir = options.tsconfigRootDir;
- }
-
- if (
- Array.isArray(options.extraFileExtensions) &&
- options.extraFileExtensions.every(ext => typeof ext === 'string')
- ) {
- extra.extraFileExtensions = options.extraFileExtensions;
- }
}
-
- if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) {
- const border = '=============';
- const versionWarning = [
- border,
- 'WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.',
- 'You may find that it works just fine, or you may not.',
- `SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`,
- `YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`,
- 'Please only submit bug reports when using the officially supported version.',
- border
- ];
- extra.log(versionWarning.join('\n\n'));
- warnedAboutTSVersion = true;
- }
-
+ /**
+ * Warn if the user is using an unsupported version of TypeScript
+ */
+ warnAboutTSVersion();
+ /**
+ * Generate a full ts.Program in order to be able to provide parser
+ * services, such as type-checking
+ */
const shouldProvideParserServices =
- shouldGenerateServices && extra.projects && extra.projects.length > 0;
+ extra.projects && extra.projects.length > 0;
const { ast, program } = getProgramAndAST(
code,
options,
shouldProvideParserServices
);
-
- extra.code = code;
-
/**
- * Convert the AST
+ * Convert the TypeScript AST to an ESTree-compatible one, and optionally preserve
+ * mappings between converted and original AST nodes
*/
const { estree, astMaps } = convert(ast, extra, shouldProvideParserServices);
-
/**
* Even if TypeScript parsed the source code ok, and we had no problems converting the AST,
* there may be other syntactic or semantic issues in the code that we can optionally report on.
@@ -334,42 +402,21 @@ function generateAST(
throw convertError(error);
}
}
-
- return {
- estree,
- program: shouldProvideParserServices ? program : undefined,
- astMaps: shouldProvideParserServices
- ? astMaps!
- : { esTreeNodeToTSNodeMap: undefined, tsNodeToESTreeNodeMap: undefined }
- };
-}
-
-//------------------------------------------------------------------------------
-// Public
-//------------------------------------------------------------------------------
-
-export const version: string = packageJSON.version;
-
-export function parse(
- code: string,
- options?: T
-) {
- if (options && options.errorOnTypeScriptSyntacticAndSemanticIssues) {
- throw new Error(
- `"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()`
- );
- }
- return generateAST(code, options).estree;
-}
-
-export function parseAndGenerateServices(code: string, options: ParserOptions) {
- const result = generateAST(code, options, /*shouldGenerateServices*/ true);
+ /**
+ * Return the converted AST and additional parser services
+ */
return {
- ast: result.estree,
+ ast: estree,
services: {
- program: result.program,
- esTreeNodeToTSNodeMap: result.astMaps.esTreeNodeToTSNodeMap,
- tsNodeToESTreeNodeMap: result.astMaps.tsNodeToESTreeNodeMap
+ program: shouldProvideParserServices ? program : undefined,
+ esTreeNodeToTSNodeMap:
+ shouldProvideParserServices && astMaps
+ ? astMaps.esTreeNodeToTSNodeMap
+ : undefined,
+ tsNodeToESTreeNodeMap:
+ shouldProvideParserServices && astMaps
+ ? astMaps.tsNodeToESTreeNodeMap
+ : undefined
}
};
}
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap
index 4509f7441037..38e378d9f7e0 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/parse.ts.snap
@@ -189,7 +189,87 @@ Object {
}
`;
-exports[`parse() non string code should correctly convert code to string 1`] = `
+exports[`parse() non string code should correctly convert code to a string for parse() 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "expression": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "raw": "12345",
+ "type": "Literal",
+ "value": 12345,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "type": "ExpressionStatement",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "sourceType": "script",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 5,
+ ],
+ "type": "Numeric",
+ "value": "12345",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
+exports[`parse() non string code should correctly convert code to a string for parseAndGenerateServices() 1`] = `
Object {
"body": Array [
Object {
diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts
index 74f02d03792c..fc7e8af99a10 100644
--- a/packages/typescript-estree/tests/lib/parse.ts
+++ b/packages/typescript-estree/tests/lib/parse.ts
@@ -57,9 +57,14 @@ describe('parse()', () => {
};
it(
- 'should correctly convert code to string',
+ 'should correctly convert code to a string for parse()',
createSnapshotTestBlock(code, config)
);
+
+ it(
+ 'should correctly convert code to a string for parseAndGenerateServices()',
+ createSnapshotTestBlock(code, config, true)
+ );
});
describe('loggerFn should be propagated to ast-converter', () => {
diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts
index eb5af8677e97..e45cae843ed5 100644
--- a/packages/typescript-estree/tests/lib/semanticInfo.ts
+++ b/packages/typescript-estree/tests/lib/semanticInfo.ts
@@ -17,6 +17,7 @@ import {
formatSnapshotName,
parseCodeAndGenerateServices
} from '../../tools/test-utils';
+import { parseAndGenerateServices } from '../../src/parser';
//------------------------------------------------------------------------------
// Setup
@@ -59,6 +60,23 @@ describe('semanticInfo', () => {
);
});
+ it(`should handle "project": "./tsconfig.json" and "project": ["./tsconfig.json"] the same`, () => {
+ const filename = testFiles[0];
+ const code = readFileSync(filename, 'utf8');
+ const options = createOptions(filename);
+ const optionsProjectString = {
+ ...options,
+ project: './tsconfig.json'
+ };
+ const optionsProjectArray = {
+ ...options,
+ project: ['./tsconfig.json']
+ };
+ expect(parseAndGenerateServices(code, optionsProjectString)).toEqual(
+ parseAndGenerateServices(code, optionsProjectArray)
+ );
+ });
+
// case-specific tests
it('isolated-file tests', () => {
const fileName = resolve(FIXTURES_DIR, 'isolated-file.src.ts');
diff --git a/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts
new file mode 100644
index 000000000000..d984007bf757
--- /dev/null
+++ b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts
@@ -0,0 +1,22 @@
+import semver from 'semver';
+import * as parser from '../../src/parser';
+
+jest.mock('semver');
+
+describe('Warn on unsupported TypeScript version', () => {
+ afterEach(() => {
+ jest.resetModules();
+ jest.resetAllMocks();
+ });
+
+ it('should warn the user if they are using an unsupported TypeScript version', () => {
+ (semver.satisfies as jest.Mock).mockReturnValue(false);
+ console.log = jest.fn();
+ parser.parse('');
+ expect(console.log).toHaveBeenCalledWith(
+ expect.stringContaining(
+ 'WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree'
+ )
+ );
+ });
+});
From 5b0b3d9edbcb3ab588a34c431037d9deece30824 Mon Sep 17 00:00:00 2001
From: James Henry
Date: Mon, 28 Jan 2019 21:35:58 -0500
Subject: [PATCH 47/88] chore: publish v1.1.1
---
CHANGELOG.md | 12 ++++++++++++
lerna.json | 2 +-
packages/eslint-plugin-tslint/CHANGELOG.md | 4 ++++
packages/eslint-plugin-tslint/package.json | 4 ++--
packages/eslint-plugin/CHANGELOG.md | 7 +++++++
packages/eslint-plugin/package.json | 4 ++--
packages/parser/CHANGELOG.md | 8 ++++++++
packages/parser/package.json | 6 +++---
packages/shared-fixtures/CHANGELOG.md | 8 ++++++++
packages/shared-fixtures/package.json | 2 +-
packages/typescript-estree/CHANGELOG.md | 11 +++++++++++
packages/typescript-estree/package.json | 4 ++--
12 files changed, 61 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6fbb5db67f5c..ccbbce028b9f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
+
+### Bug Fixes
+
+- **eslint-plugin:** make parser services error clearer ([#132](https://github.com/typescript-eslint/typescript-eslint/issues/132)) ([aa9d1e1](https://github.com/typescript-eslint/typescript-eslint/commit/aa9d1e1))
+- **parser:** add visiting of type parameters in JSXOpeningElement ([#150](https://github.com/typescript-eslint/typescript-eslint/issues/150)) ([5e16003](https://github.com/typescript-eslint/typescript-eslint/commit/5e16003))
+- **ts-estree:** expand optional property to include question token ([#138](https://github.com/typescript-eslint/typescript-eslint/issues/138)) ([9068b62](https://github.com/typescript-eslint/typescript-eslint/commit/9068b62))
+
+### Performance Improvements
+
+- **ts-estree:** don't create Program in parse() ([#148](https://github.com/typescript-eslint/typescript-eslint/issues/148)) ([aacf5b0](https://github.com/typescript-eslint/typescript-eslint/commit/aacf5b0))
+
# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
### Bug Fixes
diff --git a/lerna.json b/lerna.json
index 844b711bb0fe..06bbd031b2c8 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
{
- "version": "1.1.0",
+ "version": "1.1.1",
"npmClient": "yarn",
"useWorkspaces": true,
"stream": true
diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md
index 6b4306f26855..46f2c1960d94 100644
--- a/packages/eslint-plugin-tslint/CHANGELOG.md
+++ b/packages/eslint-plugin-tslint/CHANGELOG.md
@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
+
+**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
+
# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json
index d8aeedf6ef0e..b54084d620e4 100644
--- a/packages/eslint-plugin-tslint/package.json
+++ b/packages/eslint-plugin-tslint/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin-tslint",
- "version": "1.1.0",
+ "version": "1.1.1",
"main": "dist/index.js",
"typings": "src/index.ts",
"description": "TSLint wrapper plugin for ESLint",
@@ -34,6 +34,6 @@
"devDependencies": {
"@types/eslint": "^4.16.3",
"@types/lodash.memoize": "^4.1.4",
- "@typescript-eslint/parser": "1.1.0"
+ "@typescript-eslint/parser": "1.1.1"
}
}
diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md
index 39a512dab49e..992ae046dde3 100644
--- a/packages/eslint-plugin/CHANGELOG.md
+++ b/packages/eslint-plugin/CHANGELOG.md
@@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
+
+### Bug Fixes
+
+- **eslint-plugin:** make parser services error clearer ([#132](https://github.com/typescript-eslint/typescript-eslint/issues/132)) ([aa9d1e1](https://github.com/typescript-eslint/typescript-eslint/commit/aa9d1e1))
+- **parser:** add visiting of type parameters in JSXOpeningElement ([#150](https://github.com/typescript-eslint/typescript-eslint/issues/150)) ([5e16003](https://github.com/typescript-eslint/typescript-eslint/commit/5e16003))
+
# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
### Bug Fixes
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index 7d414aa3576d..5e824cfd98c3 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin",
- "version": "1.1.0",
+ "version": "1.1.1",
"description": "TypeScript plugin for ESLint",
"keywords": [
"eslint",
@@ -24,7 +24,7 @@
"recommended:update": "node tools/update-recommended.js"
},
"dependencies": {
- "@typescript-eslint/parser": "1.1.0",
+ "@typescript-eslint/parser": "1.1.1",
"requireindex": "^1.2.0"
},
"devDependencies": {
diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md
index 3c8b8d4e4efc..f2047e5c6d25 100644
--- a/packages/parser/CHANGELOG.md
+++ b/packages/parser/CHANGELOG.md
@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
+
+### Bug Fixes
+
+- **eslint-plugin:** make parser services error clearer ([#132](https://github.com/typescript-eslint/typescript-eslint/issues/132)) ([aa9d1e1](https://github.com/typescript-eslint/typescript-eslint/commit/aa9d1e1))
+- **parser:** add visiting of type parameters in JSXOpeningElement ([#150](https://github.com/typescript-eslint/typescript-eslint/issues/150)) ([5e16003](https://github.com/typescript-eslint/typescript-eslint/commit/5e16003))
+- **ts-estree:** expand optional property to include question token ([#138](https://github.com/typescript-eslint/typescript-eslint/issues/138)) ([9068b62](https://github.com/typescript-eslint/typescript-eslint/commit/9068b62))
+
# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
### Bug Fixes
diff --git a/packages/parser/package.json b/packages/parser/package.json
index 2ba2e642ebd9..6cf42f6ce6db 100644
--- a/packages/parser/package.json
+++ b/packages/parser/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/parser",
- "version": "1.1.0",
+ "version": "1.1.1",
"description": "An ESLint custom parser which leverages TypeScript ESTree",
"main": "dist/parser.js",
"files": [
@@ -36,7 +36,7 @@
"typescript": "*"
},
"dependencies": {
- "@typescript-eslint/typescript-estree": "1.1.0",
+ "@typescript-eslint/typescript-estree": "1.1.1",
"eslint-scope": "^4.0.0",
"eslint-visitor-keys": "^1.0.0"
},
@@ -44,6 +44,6 @@
"@types/eslint": "^4.16.5",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/estree": "^0.0.39",
- "@typescript-eslint/shared-fixtures": "1.1.0"
+ "@typescript-eslint/shared-fixtures": "1.1.1"
}
}
diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md
index 3114aaabc99c..2c81f52bfe1e 100644
--- a/packages/shared-fixtures/CHANGELOG.md
+++ b/packages/shared-fixtures/CHANGELOG.md
@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
+
+**Note:** Version bump only for package @typescript-eslint/shared-fixtures
+
+
+
+
+
# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
diff --git a/packages/shared-fixtures/package.json b/packages/shared-fixtures/package.json
index 2424070165f4..e5b8b9613aad 100644
--- a/packages/shared-fixtures/package.json
+++ b/packages/shared-fixtures/package.json
@@ -1,5 +1,5 @@
{
"name": "@typescript-eslint/shared-fixtures",
- "version": "1.1.0",
+ "version": "1.1.1",
"private": true
}
diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md
index be11f821f745..2fcfd25aae42 100644
--- a/packages/typescript-estree/CHANGELOG.md
+++ b/packages/typescript-estree/CHANGELOG.md
@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
+
+### Bug Fixes
+
+- **parser:** add visiting of type parameters in JSXOpeningElement ([#150](https://github.com/typescript-eslint/typescript-eslint/issues/150)) ([5e16003](https://github.com/typescript-eslint/typescript-eslint/commit/5e16003))
+- **ts-estree:** expand optional property to include question token ([#138](https://github.com/typescript-eslint/typescript-eslint/issues/138)) ([9068b62](https://github.com/typescript-eslint/typescript-eslint/commit/9068b62))
+
+### Performance Improvements
+
+- **ts-estree:** don't create Program in parse() ([#148](https://github.com/typescript-eslint/typescript-eslint/issues/148)) ([aacf5b0](https://github.com/typescript-eslint/typescript-eslint/commit/aacf5b0))
+
# [1.1.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.0.0...v1.1.0) (2019-01-23)
### Bug Fixes
diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json
index 3d112005adce..2be4fceecffc 100644
--- a/packages/typescript-estree/package.json
+++ b/packages/typescript-estree/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/typescript-estree",
- "version": "1.1.0",
+ "version": "1.1.1",
"description": "A parser that converts TypeScript source code into an ESTree compatible form",
"main": "dist/parser.js",
"types": "dist/parser.d.ts",
@@ -42,7 +42,7 @@
"typescript": "*"
},
"devDependencies": {
- "@typescript-eslint/shared-fixtures": "1.1.0",
+ "@typescript-eslint/shared-fixtures": "1.1.1",
"typescript": "~3.2.1"
}
}
From 38abc282ec03b907ae0eac9fae962cf262c9f885 Mon Sep 17 00:00:00 2001
From: Benjamin Lichtman
Date: Tue, 29 Jan 2019 12:58:21 -0800
Subject: [PATCH 48/88] feat(eslint-plugin): add no-unnecessary-type-assertion
rule (#157)
Adding equivalent of TSLint's `no-unnecessary-type-assertion`.
---
packages/eslint-plugin/README.md | 1 +
packages/eslint-plugin/ROADMAP.md | 8 +-
.../rules/no-unnecessary-type-assertion.md | 57 ++++++
.../rules/no-unnecessary-type-assertion.js | 179 ++++++++++++++++++
.../rules/no-unnecessary-type-assertion.js | 122 ++++++++++++
5 files changed, 363 insertions(+), 4 deletions(-)
create mode 100644 packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md
create mode 100644 packages/eslint-plugin/lib/rules/no-unnecessary-type-assertion.js
create mode 100644 packages/eslint-plugin/tests/lib/rules/no-unnecessary-type-assertion.js
diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md
index 4f6f771d47c4..09b00a8e69a6 100644
--- a/packages/eslint-plugin/README.md
+++ b/packages/eslint-plugin/README.md
@@ -105,6 +105,7 @@ See [@typescript-eslint/parser's README.md](../parser/README.md) for more inform
| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` (`no-this-assignment` from TSLint) | | |
| [`@typescript-eslint/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) | Disallow `/// ` comments (`no-reference` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases (`interface-over-type-literal` from TSLint) | | |
+| [`typescript/no-unnecessary-type-assertion`](./docs/rules/no-unnecessary-type-assertion.md) | Warns if a type assertion does not change the type of an expression (`no-unnecessary-type-assertion` from TSLint) | | :wrench: |
| [`@typescript-eslint/no-unused-vars`](./docs/rules/no-unused-vars.md) | Disallow unused variables (`no-unused-variable` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | :heavy_check_mark: | |
| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements (`no-var-requires` from TSLint) | :heavy_check_mark: | |
diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md
index 1fce16992a9c..378a3140ffb8 100644
--- a/packages/eslint-plugin/ROADMAP.md
+++ b/packages/eslint-plugin/ROADMAP.md
@@ -1,10 +1,10 @@
-# Roadmap
+# Roadmap
-✅ (27) = done
+✅ (28) = done
🌟 (79) = in ESLint core
🔌 (33) = in another plugin
🌓 (16) = implementations differ or ESLint version is missing functionality
-🛑 (71) = unimplemented
+🛑 (70) = unimplemented
## TSLint rules
@@ -26,7 +26,7 @@
| [`no-non-null-assertion`] | ✅ | [`@typescript-eslint/no-non-null-assertion`] |
| [`no-parameter-reassignment`] | ✅ | [`no-param-reassign`][no-param-reassign] |
| [`no-reference`] | ✅ | [`@typescript-eslint/no-triple-slash-reference`] |
-| [`no-unnecessary-type-assertion`] | 🛑 | N/A |
+| [`no-unnecessary-type-assertion`] | ✅ | [`@typescript-eslint/no-unnecessary-type-assertion`] |
| [`no-var-requires`] | ✅ | [`@typescript-eslint/no-var-requires`] |
| [`only-arrow-functions`] | 🔌 | [`prefer-arrow/prefer-arrow-functions`] |
| [`prefer-for-of`] | 🛑 | N/A |
diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md b/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md
new file mode 100644
index 000000000000..c41d0f2a4300
--- /dev/null
+++ b/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md
@@ -0,0 +1,57 @@
+# Warns if a type assertion does not change the type of an expression (no-unnecessary-type-assertion)
+
+This rule prohibits using a type assertion that does not change the type of an expression.
+
+## Rule Details
+
+This rule aims to prevent unnecessary type assertions.
+
+Examples of **incorrect** code for this rule:
+
+```ts
+const foo = 3;
+const bar = foo!;
+```
+
+```ts
+const foo = <3>3;
+```
+
+```ts
+type Foo = 3;
+const foo = 3;
+```
+
+```ts
+type Foo = 3;
+const foo = 3 as Foo;
+```
+
+Examples of **correct** code for this rule:
+
+```ts
+const foo = 3;
+```
+
+```ts
+const foo = 3 as number;
+```
+
+### Options
+
+This rule optionally takes an object with a single property `typesToIgnore`, which can be set to a list of type names to ignore.
+
+For example, with `@typescript-eslint/no-unnecessary-type-assertion: ["error", { typesToIgnore: ['Foo'] }]`, the following is **correct** code":
+
+```ts
+type Foo = 3;
+const foo: Foo = 3;
+```
+
+## When Not To Use It
+
+If you don't care about having no-op type assertions in your code, then you can turn off this rule.
+
+## Related to
+
+- TSLint: ['no-unnecessary-type-assertion`](https://palantir.github.io/tslint/rules/no-unnecessary-type-assertion/)
diff --git a/packages/eslint-plugin/lib/rules/no-unnecessary-type-assertion.js b/packages/eslint-plugin/lib/rules/no-unnecessary-type-assertion.js
new file mode 100644
index 000000000000..ed1747c0d95e
--- /dev/null
+++ b/packages/eslint-plugin/lib/rules/no-unnecessary-type-assertion.js
@@ -0,0 +1,179 @@
+/**
+ * @fileoverview Rule to warn if a type assertion does not change the type of an expression
+ * @author Benjamin Lichtman
+ */
+
+'use strict';
+const tsutils = require('tsutils');
+const ts = require('typescript');
+const util = require('../util');
+
+/** @typedef {import("estree").Node} Node */
+/** @typedef {import("eslint").Rule.RuleContext} Context */
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+/**
+ * Sometimes tuple types don't have ObjectFlags.Tuple set, like when they're being matched against an inferred type.
+ * So, in addition, check if there are integer properties 0..n and no other numeric keys
+ * @param {ts.ObjectType} type type
+ * @returns {boolean} true if type could be a tuple type
+ */
+function couldBeTupleType(type) {
+ const properties = type.getProperties();
+
+ if (properties.length === 0) {
+ return false;
+ }
+ let i = 0;
+
+ for (; i < properties.length; ++i) {
+ const name = properties[i].name;
+
+ if (String(i) !== name) {
+ if (i === 0) {
+ // if there are no integer properties, this is not a tuple
+ return false;
+ }
+ break;
+ }
+ }
+ for (; i < properties.length; ++i) {
+ if (String(+properties[i].name) === properties[i].name) {
+ return false; // if there are any other numeric properties, this is not a tuple
+ }
+ }
+ return true;
+}
+
+/**
+ *
+ * @param {Node} node node being linted
+ * @param {Context} context linting context
+ * @param {ts.TypeChecker} checker TypeScript typechecker
+ * @returns {void}
+ */
+function checkNonNullAssertion(node, context, checker) {
+ /**
+ * Corresponding TSNode is guaranteed to be in map
+ * @type {ts.NonNullExpression}
+ */
+ const originalNode = context.parserServices.esTreeNodeToTSNodeMap.get(node);
+ const type = checker.getTypeAtLocation(originalNode.expression);
+
+ if (type === checker.getNonNullableType(type)) {
+ context.report({
+ node,
+ messageId: 'unnecessaryAssertion',
+ fix(fixer) {
+ return fixer.removeRange([
+ originalNode.expression.end,
+ originalNode.end
+ ]);
+ }
+ });
+ }
+}
+
+/**
+ * @param {Node} node node being linted
+ * @param {Context} context linting context
+ * @param {ts.TypeChecker} checker TypeScript typechecker
+ * @returns {void}
+ */
+function verifyCast(node, context, checker) {
+ /**
+ * * Corresponding TSNode is guaranteed to be in map
+ * @type {ts.AssertionExpression}
+ */
+ const originalNode = context.parserServices.esTreeNodeToTSNodeMap.get(node);
+ const options = context.options[0];
+
+ if (
+ options &&
+ options.typesToIgnore &&
+ options.typesToIgnore.indexOf(originalNode.type.getText()) !== -1
+ ) {
+ return;
+ }
+ const castType = checker.getTypeAtLocation(originalNode);
+
+ if (
+ tsutils.isTypeFlagSet(castType, ts.TypeFlags.Literal) ||
+ (tsutils.isObjectType(castType) &&
+ (tsutils.isObjectFlagSet(castType, ts.ObjectFlags.Tuple) ||
+ couldBeTupleType(castType)))
+ ) {
+ // It's not always safe to remove a cast to a literal type or tuple
+ // type, as those types are sometimes widened without the cast.
+ return;
+ }
+
+ const uncastType = checker.getTypeAtLocation(originalNode.expression);
+
+ if (uncastType === castType) {
+ context.report({
+ node,
+ messageId: 'unnecessaryAssertion',
+ fix(fixer) {
+ return originalNode.kind === ts.SyntaxKind.TypeAssertionExpression
+ ? fixer.removeRange([
+ originalNode.getStart(),
+ originalNode.expression.getStart()
+ ])
+ : fixer.removeRange([originalNode.expression.end, originalNode.end]);
+ }
+ });
+ }
+}
+
+/** @type {import("eslint").Rule.RuleModule} */
+module.exports = {
+ meta: {
+ docs: {
+ description:
+ 'Warns if a type assertion does not change the type of an expression',
+ category: 'TypeScript-specific',
+ recommended: false,
+ extraDescription: [util.tslintRule('no-unnecessary-type-assertion')],
+ url: util.metaDocsUrl('no-unnecessary-type-assertion')
+ },
+ fixable: 'code',
+ messages: {
+ unnecessaryAssertion:
+ 'This assertion is unnecessary since it does not change the type of the expression.'
+ },
+ schema: [
+ {
+ type: 'object',
+ properties: {
+ typesToIgnore: {
+ type: 'array',
+ items: {
+ type: 'string'
+ }
+ }
+ }
+ }
+ ],
+ type: 'suggestion'
+ },
+
+ create(context) {
+ const checker = util.getParserServices(context).program.getTypeChecker();
+
+ return {
+ TSNonNullExpression(node) {
+ checkNonNullAssertion(node, context, checker);
+ },
+ TSTypeAssertion(node) {
+ verifyCast(node, context, checker);
+ },
+ TSAsExpression(node) {
+ verifyCast(node, context, checker);
+ }
+ };
+ }
+};
diff --git a/packages/eslint-plugin/tests/lib/rules/no-unnecessary-type-assertion.js b/packages/eslint-plugin/tests/lib/rules/no-unnecessary-type-assertion.js
new file mode 100644
index 000000000000..633f1a334330
--- /dev/null
+++ b/packages/eslint-plugin/tests/lib/rules/no-unnecessary-type-assertion.js
@@ -0,0 +1,122 @@
+/**
+ * @fileoverview Warns if a type assertion does not change the type of an expression.
+ * @author Benjamin Lichtman
+ */
+'use strict';
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+const rule = require('../../../lib/rules/no-unnecessary-type-assertion'),
+ RuleTester = require('eslint').RuleTester,
+ path = require('path');
+
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
+const rootDir = path.join(process.cwd(), 'tests/fixtures');
+const parserOptions = {
+ ecmaVersion: 2015,
+ tsconfigRootDir: rootDir,
+ project: './tsconfig.json'
+};
+const ruleTester = new RuleTester({
+ parserOptions,
+ parser: '@typescript-eslint/parser'
+});
+
+ruleTester.run('no-unnecessary-type-assertion', rule, {
+ valid: [
+ 'const foo = 3 as number;',
+ 'const foo = 3;',
+ 'const foo = <3>3;',
+ 'const foo = 3 as 3;',
+ `
+type Tuple = [3, "hi", "bye"];
+const foo = ([3, "hi", "bye"]) as Tuple;`,
+ `
+type PossibleTuple = {};
+const foo = ({}) as PossibleTuple;`,
+ `
+type PossibleTuple = { hello: "hello" };
+const foo = ({ hello: "hello" }) as PossibleTuple;`,
+ `
+type PossibleTuple = { 0: "hello", 5: "hello" };
+const foo = ({ 0: "hello", 5: "hello" }) as PossibleTuple;`,
+ {
+ code: `
+type Foo = number;
+const foo = (3 + 5) as Foo;`,
+ options: [{ typesToIgnore: ['Foo'] }]
+ },
+ {
+ code: `
+type Foo = number;
+const foo = (3 + 5);`,
+ options: [{ typesToIgnore: ['Foo'] }]
+ }
+ ],
+
+ invalid: [
+ {
+ code: `
+const foo = 3;
+const bar = foo!;`,
+ errors: [
+ {
+ messageId: 'unnecessaryAssertion',
+ line: 3,
+ column: 13
+ }
+ ]
+ },
+ {
+ code: `
+const foo = (3 + 5) as number;`,
+ errors: [
+ {
+ messageId: 'unnecessaryAssertion',
+ line: 2,
+ column: 13
+ }
+ ]
+ },
+ {
+ code: `
+const foo = (3 + 5);`,
+ errors: [
+ {
+ messageId: 'unnecessaryAssertion',
+ line: 2,
+ column: 13
+ }
+ ]
+ },
+ {
+ code: `
+type Foo = number;
+const foo = (3 + 5) as Foo;`,
+ errors: [
+ {
+ messageId: 'unnecessaryAssertion',
+ line: 3,
+ column: 13
+ }
+ ]
+ },
+ {
+ code: `
+type Foo = number;
+const foo = (3 + 5);`,
+ errors: [
+ {
+ messageId: 'unnecessaryAssertion',
+ line: 3,
+ column: 13
+ }
+ ]
+ }
+ ]
+});
From 6147de1bb20e269b1e0a650c8be5376d0f51752e Mon Sep 17 00:00:00 2001
From: Armano
Date: Tue, 29 Jan 2019 22:10:01 +0100
Subject: [PATCH 49/88] fix(parser): fix regression with no-unused-vars for jsx
attributes (#161)
---
.../tests/lib/rules/no-unused-vars.js | 16 +-
packages/parser/src/analyze-scope.ts | 2 +-
.../scope-analysis/jsx-attributes.tsx | 8 +
.../lib/__snapshots__/scope-analysis.ts.snap | 459 ++++++++++++++++++
4 files changed, 483 insertions(+), 2 deletions(-)
create mode 100644 packages/parser/tests/fixtures/scope-analysis/jsx-attributes.tsx
diff --git a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
index 2fe854b2c442..6aef8a1e50ad 100644
--- a/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
+++ b/packages/eslint-plugin/tests/lib/rules/no-unused-vars.js
@@ -558,8 +558,8 @@ import foo from 'foo';
import bar from 'foo';
export interface Bar extends foo.i18n {}
`,
- // https://github.com/typescript-eslint/typescript-eslint/issues/141
{
+ // https://github.com/typescript-eslint/typescript-eslint/issues/141
filename: 'test.tsx',
code: `
import { TypeA } from './interface';
@@ -570,6 +570,20 @@ export const a = />;
jsx: true
}
}
+ },
+ {
+ // https://github.com/typescript-eslint/typescript-eslint/issues/160
+ filename: 'test.tsx',
+ code: `
+const text = 'text';
+export function Foo() {
+ return (
+
+
+
+ );
+}
+ `
}
],
diff --git a/packages/parser/src/analyze-scope.ts b/packages/parser/src/analyze-scope.ts
index eb9f3c92c752..2e8ae2e0a3cd 100644
--- a/packages/parser/src/analyze-scope.ts
+++ b/packages/parser/src/analyze-scope.ts
@@ -241,7 +241,7 @@ class Referencer extends OriginalReferencer {
JSXOpeningElement(node: any) {
this.visit(node.name);
this.visitTypeParameters(node);
- this.visit(node.attributes);
+ node.attributes.forEach(this.visit, this);
}
/**
diff --git a/packages/parser/tests/fixtures/scope-analysis/jsx-attributes.tsx b/packages/parser/tests/fixtures/scope-analysis/jsx-attributes.tsx
new file mode 100644
index 000000000000..04bb4b42ac80
--- /dev/null
+++ b/packages/parser/tests/fixtures/scope-analysis/jsx-attributes.tsx
@@ -0,0 +1,8 @@
+const text = 'text';
+export function Foo() {
+ return (
+
+
+
+ );
+}
diff --git a/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap b/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap
index 8fd73916d216..39fedcb8277b 100644
--- a/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/scope-analysis.ts.snap
@@ -5325,6 +5325,248 @@ Object {
}
`;
+exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/jsx-attributes.tsx 1`] = `
+Object {
+ "$id": 7,
+ "block": Object {
+ "range": Array [
+ 0,
+ 143,
+ ],
+ "type": "Program",
+ },
+ "childScopes": Array [
+ Object {
+ "$id": 6,
+ "block": Object {
+ "range": Array [
+ 0,
+ 143,
+ ],
+ "type": "Program",
+ },
+ "childScopes": Array [
+ Object {
+ "$id": 5,
+ "block": Object {
+ "range": Array [
+ 28,
+ 142,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ "childScopes": Array [],
+ "functionExpressionScope": false,
+ "isStrict": true,
+ "references": Array [
+ Object {
+ "$id": 4,
+ "from": Object {
+ "$ref": 5,
+ },
+ "identifier": Object {
+ "name": "text",
+ "range": Array [
+ 116,
+ 120,
+ ],
+ "type": "Identifier",
+ },
+ "kind": "r",
+ "resolved": Object {
+ "$ref": 0,
+ },
+ "writeExpr": undefined,
+ },
+ ],
+ "throughReferences": Array [
+ Object {
+ "$ref": 4,
+ },
+ ],
+ "type": "function",
+ "upperScope": Object {
+ "$ref": 6,
+ },
+ "variableMap": Object {
+ "arguments": Object {
+ "$ref": 3,
+ },
+ },
+ "variableScope": Object {
+ "$ref": 5,
+ },
+ "variables": Array [
+ Object {
+ "$id": 3,
+ "defs": Array [],
+ "eslintUsed": undefined,
+ "identifiers": Array [],
+ "name": "arguments",
+ "references": Array [],
+ "scope": Object {
+ "$ref": 5,
+ },
+ },
+ ],
+ },
+ ],
+ "functionExpressionScope": false,
+ "isStrict": true,
+ "references": Array [
+ Object {
+ "$id": 2,
+ "from": Object {
+ "$ref": 6,
+ },
+ "identifier": Object {
+ "name": "text",
+ "range": Array [
+ 6,
+ 10,
+ ],
+ "type": "Identifier",
+ },
+ "kind": "w",
+ "resolved": Object {
+ "$ref": 0,
+ },
+ "writeExpr": Object {
+ "range": Array [
+ 13,
+ 19,
+ ],
+ "type": "Literal",
+ },
+ },
+ ],
+ "throughReferences": Array [],
+ "type": "module",
+ "upperScope": Object {
+ "$ref": 7,
+ },
+ "variableMap": Object {
+ "Foo": Object {
+ "$ref": 1,
+ },
+ "text": Object {
+ "$ref": 0,
+ },
+ },
+ "variableScope": Object {
+ "$ref": 6,
+ },
+ "variables": Array [
+ Object {
+ "$id": 0,
+ "defs": Array [
+ Object {
+ "name": Object {
+ "name": "text",
+ "range": Array [
+ 6,
+ 10,
+ ],
+ "type": "Identifier",
+ },
+ "node": Object {
+ "range": Array [
+ 6,
+ 19,
+ ],
+ "type": "VariableDeclarator",
+ },
+ "parent": Object {
+ "range": Array [
+ 0,
+ 20,
+ ],
+ "type": "VariableDeclaration",
+ },
+ "type": "Variable",
+ },
+ ],
+ "eslintUsed": undefined,
+ "identifiers": Array [
+ Object {
+ "name": "text",
+ "range": Array [
+ 6,
+ 10,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "name": "text",
+ "references": Array [
+ Object {
+ "$ref": 2,
+ },
+ Object {
+ "$ref": 4,
+ },
+ ],
+ "scope": Object {
+ "$ref": 6,
+ },
+ },
+ Object {
+ "$id": 1,
+ "defs": Array [
+ Object {
+ "name": Object {
+ "name": "Foo",
+ "range": Array [
+ 37,
+ 40,
+ ],
+ "type": "Identifier",
+ },
+ "node": Object {
+ "range": Array [
+ 28,
+ 142,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ "parent": null,
+ "type": "FunctionName",
+ },
+ ],
+ "eslintUsed": undefined,
+ "identifiers": Array [
+ Object {
+ "name": "Foo",
+ "range": Array [
+ 37,
+ 40,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "name": "Foo",
+ "references": Array [],
+ "scope": Object {
+ "$ref": 6,
+ },
+ },
+ ],
+ },
+ ],
+ "functionExpressionScope": false,
+ "isStrict": false,
+ "references": Array [],
+ "throughReferences": Array [],
+ "type": "global",
+ "upperScope": null,
+ "variableMap": Object {},
+ "variableScope": Object {
+ "$ref": 7,
+ },
+ "variables": Array [],
+}
+`;
+
exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/method-overload.ts 1`] = `
Object {
"$id": 11,
@@ -15626,6 +15868,223 @@ Object {
}
`;
+exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/jsx-attributes.tsx 1`] = `
+Object {
+ "$id": 6,
+ "block": Object {
+ "range": Array [
+ 0,
+ 143,
+ ],
+ "type": "Program",
+ },
+ "childScopes": Array [
+ Object {
+ "$id": 5,
+ "block": Object {
+ "range": Array [
+ 28,
+ 142,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ "childScopes": Array [],
+ "functionExpressionScope": false,
+ "isStrict": false,
+ "references": Array [
+ Object {
+ "$id": 4,
+ "from": Object {
+ "$ref": 5,
+ },
+ "identifier": Object {
+ "name": "text",
+ "range": Array [
+ 116,
+ 120,
+ ],
+ "type": "Identifier",
+ },
+ "kind": "r",
+ "resolved": Object {
+ "$ref": 0,
+ },
+ "writeExpr": undefined,
+ },
+ ],
+ "throughReferences": Array [
+ Object {
+ "$ref": 4,
+ },
+ ],
+ "type": "function",
+ "upperScope": Object {
+ "$ref": 6,
+ },
+ "variableMap": Object {
+ "arguments": Object {
+ "$ref": 3,
+ },
+ },
+ "variableScope": Object {
+ "$ref": 5,
+ },
+ "variables": Array [
+ Object {
+ "$id": 3,
+ "defs": Array [],
+ "eslintUsed": undefined,
+ "identifiers": Array [],
+ "name": "arguments",
+ "references": Array [],
+ "scope": Object {
+ "$ref": 5,
+ },
+ },
+ ],
+ },
+ ],
+ "functionExpressionScope": false,
+ "isStrict": false,
+ "references": Array [
+ Object {
+ "$id": 2,
+ "from": Object {
+ "$ref": 6,
+ },
+ "identifier": Object {
+ "name": "text",
+ "range": Array [
+ 6,
+ 10,
+ ],
+ "type": "Identifier",
+ },
+ "kind": "w",
+ "resolved": Object {
+ "$ref": 0,
+ },
+ "writeExpr": Object {
+ "range": Array [
+ 13,
+ 19,
+ ],
+ "type": "Literal",
+ },
+ },
+ ],
+ "throughReferences": Array [],
+ "type": "global",
+ "upperScope": null,
+ "variableMap": Object {
+ "Foo": Object {
+ "$ref": 1,
+ },
+ "text": Object {
+ "$ref": 0,
+ },
+ },
+ "variableScope": Object {
+ "$ref": 6,
+ },
+ "variables": Array [
+ Object {
+ "$id": 0,
+ "defs": Array [
+ Object {
+ "name": Object {
+ "name": "text",
+ "range": Array [
+ 6,
+ 10,
+ ],
+ "type": "Identifier",
+ },
+ "node": Object {
+ "range": Array [
+ 6,
+ 19,
+ ],
+ "type": "VariableDeclarator",
+ },
+ "parent": Object {
+ "range": Array [
+ 0,
+ 20,
+ ],
+ "type": "VariableDeclaration",
+ },
+ "type": "Variable",
+ },
+ ],
+ "eslintUsed": undefined,
+ "identifiers": Array [
+ Object {
+ "name": "text",
+ "range": Array [
+ 6,
+ 10,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "name": "text",
+ "references": Array [
+ Object {
+ "$ref": 2,
+ },
+ Object {
+ "$ref": 4,
+ },
+ ],
+ "scope": Object {
+ "$ref": 6,
+ },
+ },
+ Object {
+ "$id": 1,
+ "defs": Array [
+ Object {
+ "name": Object {
+ "name": "Foo",
+ "range": Array [
+ 37,
+ 40,
+ ],
+ "type": "Identifier",
+ },
+ "node": Object {
+ "range": Array [
+ 28,
+ 142,
+ ],
+ "type": "FunctionDeclaration",
+ },
+ "parent": null,
+ "type": "FunctionName",
+ },
+ ],
+ "eslintUsed": undefined,
+ "identifiers": Array [
+ Object {
+ "name": "Foo",
+ "range": Array [
+ 37,
+ 40,
+ ],
+ "type": "Identifier",
+ },
+ ],
+ "name": "Foo",
+ "references": Array [],
+ "scope": Object {
+ "$ref": 6,
+ },
+ },
+ ],
+}
+`;
+
exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/method-overload.ts 1`] = `
Object {
"$id": 10,
From f8f9b90d6941cf6138a08275e0ba10d8a86f82aa Mon Sep 17 00:00:00 2001
From: Veniamin Krol <153412+vkrol@users.noreply.github.com>
Date: Wed, 30 Jan 2019 15:07:11 +0200
Subject: [PATCH 50/88] docs(eslint-plugin): no-unnecessary-type-assertion rule
name in README.md (#163)
---
packages/eslint-plugin/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md
index 09b00a8e69a6..6766e831a3f4 100644
--- a/packages/eslint-plugin/README.md
+++ b/packages/eslint-plugin/README.md
@@ -105,7 +105,7 @@ See [@typescript-eslint/parser's README.md](../parser/README.md) for more inform
| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` (`no-this-assignment` from TSLint) | | |
| [`@typescript-eslint/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) | Disallow `/// ` comments (`no-reference` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases (`interface-over-type-literal` from TSLint) | | |
-| [`typescript/no-unnecessary-type-assertion`](./docs/rules/no-unnecessary-type-assertion.md) | Warns if a type assertion does not change the type of an expression (`no-unnecessary-type-assertion` from TSLint) | | :wrench: |
+| [`@typescript-eslint/no-unnecessary-type-assertion`](./docs/rules/no-unnecessary-type-assertion.md) | Warns if a type assertion does not change the type of an expression (`no-unnecessary-type-assertion` from TSLint) | | :wrench: |
| [`@typescript-eslint/no-unused-vars`](./docs/rules/no-unused-vars.md) | Disallow unused variables (`no-unused-variable` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | :heavy_check_mark: | |
| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements (`no-var-requires` from TSLint) | :heavy_check_mark: | |
From c779ad489b9176033a9fe7ceb722ff9847d51d35 Mon Sep 17 00:00:00 2001
From: Jed Fox
Date: Wed, 30 Jan 2019 08:25:11 -0500
Subject: [PATCH 51/88] docs(eslint-plugin): add docs on using Prettier with
the plugin (#104)
---
packages/eslint-plugin/README.md | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md
index 6766e831a3f4..f0c11446353e 100644
--- a/packages/eslint-plugin/README.md
+++ b/packages/eslint-plugin/README.md
@@ -68,6 +68,22 @@ If you want to use rules which require type information, you will need to specif
See [@typescript-eslint/parser's README.md](../parser/README.md) for more information on the available "parserOptions".
+## Usage with Prettier
+
+Install [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) to disable our code formatting related rules:
+
+```json
+{
+ "extends": [
+ "plugin:@typescript-eslint/recommended",
+ "prettier",
+ "prettier/@typescript-eslint"
+ ]
+}
+```
+
+**Note: Make sure you have `eslint-config-prettier@4.0.0` or newer.**
+
## Supported Rules
From 417c7fb1c7c66108822b41152fb0c019152acabd Mon Sep 17 00:00:00 2001
From: James Henry
Date: Wed, 30 Jan 2019 08:39:11 -0500
Subject: [PATCH 52/88] docs(readme): add notes about package versions (#164)
---
README.md | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/README.md b/README.md
index de2fdd5da6ae..75e75658d069 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,20 @@ This repo contains several packages which allow ESLint users to lint their TypeS
- [`@typescript-eslint/eslint-plugin-tslint`](./packages/eslint-plugin-tslint) - An ESLint-specific plugin which runs an instance of TSLint within your ESLint setup to allow for users to more easily migrate from TSLint to ESLint.
+## Package Versions
+
+All of the packages are published with the same version number to make it easier to coordinate both releases and installations.
+
+Additionally, we also publish a canary release on every successful merge to master, so you never need to wait for a new stable version to make use of any updates.
+
+The `latest` (stable) version is:
+
+
+
+The `canary` (latest master) version is:
+
+
+
## Supported TypeScript Version
We will always endeavor to support the latest stable version of TypeScript.
From f0dddbc19cbbbba409d48c111d19e24f00db5073 Mon Sep 17 00:00:00 2001
From: Benjamin Lichtman
Date: Wed, 30 Jan 2019 11:34:13 -0800
Subject: [PATCH 53/88] chore(eslint-plugin): add tsutils as dependency (#165)
Managed to forget to add `tsutils` as a true dependency to `eslint-plugin` in #157.
---
packages/eslint-plugin/package.json | 3 ++-
yarn.lock | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index 5e824cfd98c3..350da0cb2aff 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -25,7 +25,8 @@
},
"dependencies": {
"@typescript-eslint/parser": "1.1.1",
- "requireindex": "^1.2.0"
+ "requireindex": "^1.2.0",
+ "tsutils": "^3.7.0"
},
"devDependencies": {
"eslint": "^5.9.0",
diff --git a/yarn.lock b/yarn.lock
index b6a6d614dfc0..6980f52cafb8 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7025,6 +7025,13 @@ tsutils@^2.27.2:
dependencies:
tslib "^1.8.1"
+tsutils@^3.7.0:
+ version "3.7.0"
+ resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.7.0.tgz#f97bdd2f109070bd1865467183e015b25734b477"
+ integrity sha512-n+e+3q7Jx2kfZw7tjfI9axEIWBY0sFMOlC+1K70X0SeXpO/UYSB+PN+E9tIJNqViB7oiXQdqD7dNchnvoneZew==
+ dependencies:
+ tslib "^1.8.1"
+
tunnel-agent@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
From 1f868cec3d6279beb24094f77c8e72626ce6fb9f Mon Sep 17 00:00:00 2001
From: Armano
Date: Thu, 31 Jan 2019 22:58:38 +0100
Subject: [PATCH 54/88] fix(eslint-plugin): use bracket for infer type in
array-type rule (#173)
---
.../eslint-plugin/lib/rules/array-type.js | 1 +
.../tests/lib/rules/array-type.js | 38 +++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/packages/eslint-plugin/lib/rules/array-type.js b/packages/eslint-plugin/lib/rules/array-type.js
index 9d30f23cfb4f..ba7d83a5a7f5 100644
--- a/packages/eslint-plugin/lib/rules/array-type.js
+++ b/packages/eslint-plugin/lib/rules/array-type.js
@@ -67,6 +67,7 @@ function typeNeedsParentheses(node) {
case 'TSFunctionType':
case 'TSIntersectionType':
case 'TSTypeOperator':
+ case 'TSInferType':
return true;
default:
return false;
diff --git a/packages/eslint-plugin/tests/lib/rules/array-type.js b/packages/eslint-plugin/tests/lib/rules/array-type.js
index e39796f90c0d..39716675cf1c 100644
--- a/packages/eslint-plugin/tests/lib/rules/array-type.js
+++ b/packages/eslint-plugin/tests/lib/rules/array-type.js
@@ -138,6 +138,11 @@ ruleTester.run('array-type', rule, {
}`,
options: ['array']
},
+ {
+ // https://github.com/typescript-eslint/typescript-eslint/issues/172
+ code: 'type Unwrap = T extends (infer E)[] ? E : T',
+ options: ['array']
+ },
{
code: `let z: Array = [3, "4"];`,
options: ['generic']
@@ -173,6 +178,11 @@ ruleTester.run('array-type', rule, {
{
code: `type fooIntersection = Array;`,
options: ['generic']
+ },
+ {
+ // https://github.com/typescript-eslint/typescript-eslint/issues/172
+ code: 'type Unwrap = T extends Array ? E : T',
+ options: ['generic']
}
],
invalid: [
@@ -774,6 +784,34 @@ let yyyy: Arr>>> = [[[["2"]]]];`,
column: 19
}
]
+ },
+ {
+ // https://github.com/typescript-eslint/typescript-eslint/issues/172
+ code: 'type Unwrap = T extends Array ? E : T',
+ output: 'type Unwrap = T extends (infer E)[] ? E : T',
+ options: ['array'],
+ errors: [
+ {
+ messageId: 'errorStringArray',
+ data: { type: 'T' },
+ line: 1,
+ column: 28
+ }
+ ]
+ },
+ {
+ // https://github.com/typescript-eslint/typescript-eslint/issues/172
+ code: 'type Unwrap = T extends (infer E)[] ? E : T',
+ output: 'type Unwrap = T extends Array ? E : T',
+ options: ['generic'],
+ errors: [
+ {
+ messageId: 'errorStringGeneric',
+ data: { type: 'T' },
+ line: 1,
+ column: 28
+ }
+ ]
}
]
});
From b1dbb648e529d43bfcc2b6581348420af5eb8736 Mon Sep 17 00:00:00 2001
From: Armano
Date: Thu, 31 Jan 2019 23:23:57 +0100
Subject: [PATCH 55/88] fix(eslint-plugin): fix no-extraneous-class for class
without name (#174)
---
.../eslint-plugin/lib/rules/no-extraneous-class.js | 12 +++++++++---
.../tests/lib/rules/no-extraneous-class.js | 10 ++++++++--
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/packages/eslint-plugin/lib/rules/no-extraneous-class.js b/packages/eslint-plugin/lib/rules/no-extraneous-class.js
index e2eb3f0216dc..0690fc3963de 100644
--- a/packages/eslint-plugin/lib/rules/no-extraneous-class.js
+++ b/packages/eslint-plugin/lib/rules/no-extraneous-class.js
@@ -68,7 +68,10 @@ module.exports = {
if (node.body.length === 0) {
if (allowEmpty) return;
- context.report({ node: id, messageId: 'empty' });
+ context.report({
+ node: id || node.parent,
+ messageId: 'empty'
+ });
return;
}
@@ -97,14 +100,17 @@ module.exports = {
if (onlyConstructor) {
if (!allowConstructorOnly) {
context.report({
- node: id,
+ node: id || node.parent,
messageId: 'onlyConstructor'
});
}
return;
}
if (onlyStatic && !allowStaticOnly) {
- context.report({ node: id, messageId: 'onlyStatic' });
+ context.report({
+ node: id || node.parent,
+ messageId: 'onlyStatic'
+ });
}
}
};
diff --git a/packages/eslint-plugin/tests/lib/rules/no-extraneous-class.js b/packages/eslint-plugin/tests/lib/rules/no-extraneous-class.js
index 4243677a8679..713e5224ccb1 100644
--- a/packages/eslint-plugin/tests/lib/rules/no-extraneous-class.js
+++ b/packages/eslint-plugin/tests/lib/rules/no-extraneous-class.js
@@ -70,7 +70,9 @@ export class Bar {
}
`.trim(),
options: [{ allowStaticOnly: true }]
- }
+ },
+ // https://github.com/typescript-eslint/typescript-eslint/issues/170
+ 'export default class { hello() { return "I am foo!"; } }'
],
invalid: [
@@ -117,9 +119,13 @@ export class AClass {
}
}
}
-
`.trim(),
errors: [onlyStatic, empty]
+ },
+ {
+ // https://github.com/typescript-eslint/typescript-eslint/issues/170
+ code: 'export default class { static hello() {} }',
+ errors: [{ messageId: 'onlyStatic', type: 'ClassDeclaration' }]
}
]
});
From 1ecc2f2fd8dd9feb578f63c53b3916210dd96797 Mon Sep 17 00:00:00 2001
From: Armano
Date: Fri, 1 Feb 2019 02:06:02 +0100
Subject: [PATCH 56/88] test(eslint-plugin): add test case for eslint
arrow-parens (#176)
---
.../tests/lib/eslint-rules/arrow-parens.js | 44 +++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 packages/eslint-plugin/tests/lib/eslint-rules/arrow-parens.js
diff --git a/packages/eslint-plugin/tests/lib/eslint-rules/arrow-parens.js b/packages/eslint-plugin/tests/lib/eslint-rules/arrow-parens.js
new file mode 100644
index 000000000000..e8a77ca2013d
--- /dev/null
+++ b/packages/eslint-plugin/tests/lib/eslint-rules/arrow-parens.js
@@ -0,0 +1,44 @@
+'use strict';
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+const rule = require('eslint/lib/rules/arrow-parens'),
+ RuleTester = require('eslint').RuleTester;
+
+const ruleTester = new RuleTester({
+ parser: '@typescript-eslint/parser'
+});
+
+ruleTester.run('arrow-parens', rule, {
+ valid: [
+ // https://github.com/typescript-eslint/typescript-eslint/issues/14
+ 'const foo = (t) => {};',
+ 'const foo = (t) => {};',
+ 'const foo = (t: T) => {};',
+ 'const foo = ((t: T) => {});',
+ 'const foo = function (t: T) {};',
+ {
+ code: 'const foo = t => {};',
+ options: ['as-needed']
+ },
+ {
+ code: 'const foo = (t) => {};',
+ options: ['as-needed']
+ },
+ {
+ code: 'const foo = (t: T) => {};',
+ options: ['as-needed']
+ },
+ {
+ code: 'const foo = (t: T) => {};',
+ options: ['as-needed']
+ },
+ {
+ code: 'const foo = (t: T) => ({});',
+ options: ['as-needed', { requireForBlockBody: true }]
+ }
+ ],
+ invalid: []
+});
From 00d020d991f5bc10dd49d9704449660af50cb61d Mon Sep 17 00:00:00 2001
From: Toru Nagashima
Date: Fri, 1 Feb 2019 21:33:53 +0900
Subject: [PATCH 57/88] fix(eslint-plugin): fix wrong URL (#180)
---
packages/eslint-plugin/lib/util.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/eslint-plugin/lib/util.js b/packages/eslint-plugin/lib/util.js
index e12e15f80413..dac41fe21bb7 100644
--- a/packages/eslint-plugin/lib/util.js
+++ b/packages/eslint-plugin/lib/util.js
@@ -5,7 +5,7 @@ const version = require('../package.json').version;
exports.tslintRule = name => `\`${name}\` from TSLint`;
exports.metaDocsUrl = name =>
- `https://github.com/typescript-eslint/typescript-eslint/blob/${version}/packages/eslint-plugin/docs/rules/${name}.md`;
+ `https://github.com/typescript-eslint/typescript-eslint/blob/v${version}/packages/eslint-plugin/docs/rules/${name}.md`;
/**
* Check if the context file name is *.ts or *.tsx
From 3fb57a5676cdbe41f75e4dc42472986cb8881993 Mon Sep 17 00:00:00 2001
From: Armano
Date: Fri, 1 Feb 2019 13:39:31 +0100
Subject: [PATCH 58/88] feat(eslint-plugin): add eslint rule
no-useless-constructor (#167)
---
packages/eslint-plugin/README.md | 3 +-
.../docs/rules/no-useless-constructor.md | 78 ++++++++++++++
.../lib/rules/no-useless-constructor.js | 80 ++++++++++++++
.../tests/lib/rules/no-useless-constructor.js | 100 ++++++++++++++++++
4 files changed, 260 insertions(+), 1 deletion(-)
create mode 100644 packages/eslint-plugin/docs/rules/no-useless-constructor.md
create mode 100644 packages/eslint-plugin/lib/rules/no-useless-constructor.js
create mode 100644 packages/eslint-plugin/tests/lib/rules/no-useless-constructor.js
diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md
index f0c11446353e..1ec6df216048 100644
--- a/packages/eslint-plugin/README.md
+++ b/packages/eslint-plugin/README.md
@@ -121,9 +121,10 @@ Install [`eslint-config-prettier`](https://github.com/prettier/eslint-config-pre
| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` (`no-this-assignment` from TSLint) | | |
| [`@typescript-eslint/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) | Disallow `/// ` comments (`no-reference` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases (`interface-over-type-literal` from TSLint) | | |
-| [`@typescript-eslint/no-unnecessary-type-assertion`](./docs/rules/no-unnecessary-type-assertion.md) | Warns if a type assertion does not change the type of an expression (`no-unnecessary-type-assertion` from TSLint) | | :wrench: |
+| [`@typescript-eslint/no-unnecessary-type-assertion`](./docs/rules/no-unnecessary-type-assertion.md) | Warns if a type assertion does not change the type of an expression (`no-unnecessary-type-assertion` from TSLint) | | :wrench: |
| [`@typescript-eslint/no-unused-vars`](./docs/rules/no-unused-vars.md) | Disallow unused variables (`no-unused-variable` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | :heavy_check_mark: | |
+| [`@typescript-eslint/no-useless-constructor`](./docs/rules/no-useless-constructor.md) | Disallow unnecessary constructors | | |
| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements (`no-var-requires` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/prefer-interface`](./docs/rules/prefer-interface.md) | Prefer an interface declaration over a type literal (type T = { ... }) (`interface-over-type-literal` from TSLint) | :heavy_check_mark: | :wrench: |
| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (`no-internal-module` from TSLint) | :heavy_check_mark: | :wrench: |
diff --git a/packages/eslint-plugin/docs/rules/no-useless-constructor.md b/packages/eslint-plugin/docs/rules/no-useless-constructor.md
new file mode 100644
index 000000000000..0e136d122ac1
--- /dev/null
+++ b/packages/eslint-plugin/docs/rules/no-useless-constructor.md
@@ -0,0 +1,78 @@
+# Disallow unnecessary constructors (no-useless-constructor)
+
+ES2015 provides a default class constructor if one is not specified. As such, it is unnecessary to provide an empty constructor or one that simply delegates into its parent class, as in the following examples:
+
+```js
+class A {
+ constructor() {}
+}
+
+class A extends B {
+ constructor(value) {
+ super(value);
+ }
+}
+```
+
+## Rule Details
+
+This rule flags class constructors that can be safely removed without changing how the class works.
+
+## Examples
+
+Examples of **incorrect** code for this rule:
+
+```js
+/*eslint no-useless-constructor: "error"*/
+
+class A {
+ constructor() {}
+}
+
+class A extends B {
+ constructor(...args) {
+ super(...args);
+ }
+}
+```
+
+Examples of **correct** code for this rule:
+
+```js
+/*eslint no-useless-constructor: "error"*/
+
+class A {}
+
+class A {
+ constructor() {
+ doSomething();
+ }
+}
+
+class A extends B {
+ constructor() {
+ super('foo');
+ }
+}
+
+class A extends B {
+ constructor() {
+ super();
+ doSomething();
+ }
+}
+
+class A extends B {
+ constructor(protected name: string) {}
+}
+
+class A extends B {
+ protected constructor() {}
+}
+```
+
+## When Not To Use It
+
+If you don't want to be notified about unnecessary constructors, you can safely disable this rule.
+
+Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-useless-constructor.md)
diff --git a/packages/eslint-plugin/lib/rules/no-useless-constructor.js b/packages/eslint-plugin/lib/rules/no-useless-constructor.js
new file mode 100644
index 000000000000..c30cdcf872bf
--- /dev/null
+++ b/packages/eslint-plugin/lib/rules/no-useless-constructor.js
@@ -0,0 +1,80 @@
+/**
+ * @fileoverview Disallow unnecessary constructors
+ * @author Armano
+ */
+'use strict';
+
+const baseRule = require('eslint/lib/rules/no-useless-constructor');
+const util = require('../util');
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+/**
+ * Check if method with accessibility is not useless
+ * @param {MethodDefinition} node
+ * @returns {boolean}
+ */
+function checkAccessibility(node) {
+ switch (node.accessibility) {
+ case 'protected':
+ case 'private':
+ return false;
+ case 'public':
+ if (
+ node.parent.type === 'ClassBody' &&
+ node.parent.parent &&
+ node.parent.parent.superClass
+ ) {
+ return false;
+ }
+ break;
+ }
+ return true;
+}
+
+/**
+ * Check if method is not unless due to typescript parameter properties
+ * @param {MethodDefinition} node
+ * @returns {boolean}
+ */
+function checkParams(node) {
+ return (
+ !node.value.params ||
+ !node.value.params.some(param => param.type === 'TSParameterProperty')
+ );
+}
+
+module.exports = Object.assign({}, baseRule, {
+ meta: {
+ type: 'problem',
+ docs: {
+ description: 'Disallow unnecessary constructors',
+ category: 'ECMAScript 6',
+ url: util.metaDocsUrl('no-useless-constructor')
+ },
+ schema: baseRule.meta.schema,
+ messages: baseRule.meta.messages
+ },
+
+ create(context) {
+ const rules = baseRule.create(context);
+
+ //----------------------------------------------------------------------
+ // Public
+ //----------------------------------------------------------------------
+ return {
+ MethodDefinition(node) {
+ if (
+ node.value &&
+ node.value.type === 'FunctionExpression' &&
+ checkAccessibility(node) &&
+ checkParams(node)
+ ) {
+ rules.MethodDefinition(node);
+ }
+ }
+ };
+ }
+});
diff --git a/packages/eslint-plugin/tests/lib/rules/no-useless-constructor.js b/packages/eslint-plugin/tests/lib/rules/no-useless-constructor.js
new file mode 100644
index 000000000000..c73c5034f121
--- /dev/null
+++ b/packages/eslint-plugin/tests/lib/rules/no-useless-constructor.js
@@ -0,0 +1,100 @@
+'use strict';
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+const rule = require('../../../lib/rules/no-useless-constructor'),
+ RuleTester = require('eslint').RuleTester;
+
+const ruleTester = new RuleTester({
+ parserOptions: {
+ ecmaVersion: 6,
+ sourceType: 'module'
+ },
+ parser: '@typescript-eslint/parser'
+});
+
+const error = { message: 'Useless constructor.', type: 'MethodDefinition' };
+
+ruleTester.run('no-useless-constructor', rule, {
+ valid: [
+ 'class A { }',
+ 'class A { constructor(){ doSomething(); } }',
+ 'class A extends B { constructor(){} }',
+ "class A extends B { constructor(){ super('foo'); } }",
+ 'class A extends B { constructor(foo, bar){ super(foo, bar, 1); } }',
+ 'class A extends B { constructor(){ super(); doSomething(); } }',
+ 'class A extends B { constructor(...args){ super(...args); doSomething(); } }',
+ 'class A { dummyMethod(){ doSomething(); } }',
+ 'class A extends B.C { constructor() { super(foo); } }',
+ 'class A extends B.C { constructor([a, b, c]) { super(...arguments); } }',
+ 'class A extends B.C { constructor(a = f()) { super(...arguments); } }',
+ 'class A extends B { constructor(a, b, c) { super(a, b); } }',
+ 'class A extends B { constructor(foo, bar){ super(foo); } }',
+ 'class A extends B { constructor(test) { super(); } }',
+ 'class A extends B { constructor() { foo; } }',
+ 'class A extends B { constructor(foo, bar) { super(bar); } }',
+ // https://github.com/typescript-eslint/typescript-eslint/issues/15
+ 'declare class A { constructor(); }',
+ 'class A { constructor(); }',
+ 'abstract class A { constructor(); }',
+ 'abstract class A { abstract constructor(); }',
+ // https://github.com/typescript-eslint/typescript-eslint/issues/48
+ 'class A { constructor(private name: string) {} }',
+ 'class A { constructor(public name: string) {} }',
+ 'class A { constructor(protected name: string) {} }',
+ // https://github.com/typescript-eslint/typescript-eslint/pull/167#discussion_r252638401
+ 'class A { private constructor() {} }',
+ 'class A { protected constructor() {} }',
+ 'class A extends B { public constructor() {} }',
+ 'class A extends B { protected constructor(foo, bar) { super(bar); } }',
+ 'class A extends B { private constructor(foo, bar) { super(bar); } }',
+ 'class A extends B { public constructor(foo){ super(foo); } }',
+ 'class A extends B { public constructor(foo){} }'
+ ],
+ invalid: [
+ {
+ code: 'class A { constructor(){} }',
+ errors: [error]
+ },
+ {
+ code: "class A { 'constructor'(){} }",
+ errors: [error]
+ },
+ {
+ code: 'class A extends B { constructor() { super(); } }',
+ errors: [error]
+ },
+ {
+ code: 'class A extends B { constructor(foo){ super(foo); } }',
+ errors: [error]
+ },
+ {
+ code: 'class A extends B { constructor(foo, bar){ super(foo, bar); } }',
+ errors: [error]
+ },
+ {
+ code: 'class A extends B { constructor(...args){ super(...args); } }',
+ errors: [error]
+ },
+ {
+ code: 'class A extends B.C { constructor() { super(...arguments); } }',
+ errors: [error]
+ },
+ {
+ code:
+ 'class A extends B { constructor(a, b, ...c) { super(...arguments); } }',
+ errors: [error]
+ },
+ {
+ code:
+ 'class A extends B { constructor(a, b, ...c) { super(a, b, ...c); } }',
+ errors: [error]
+ },
+ {
+ code: 'class A { public constructor() {} }',
+ errors: [error]
+ }
+ ]
+});
From 76600a53e0695b3d1051cb6e6a2b8802631438c2 Mon Sep 17 00:00:00 2001
From: James Henry
Date: Fri, 1 Feb 2019 07:44:18 -0500
Subject: [PATCH 59/88] chore: publish v1.2.0
---
CHANGELOG.md | 14 ++++++++++++++
lerna.json | 2 +-
packages/eslint-plugin-tslint/CHANGELOG.md | 4 ++++
packages/eslint-plugin-tslint/package.json | 4 ++--
packages/eslint-plugin/CHANGELOG.md | 14 ++++++++++++++
packages/eslint-plugin/package.json | 4 ++--
packages/parser/CHANGELOG.md | 6 ++++++
packages/parser/package.json | 6 +++---
packages/shared-fixtures/CHANGELOG.md | 8 ++++++++
packages/shared-fixtures/package.json | 2 +-
packages/typescript-estree/CHANGELOG.md | 4 ++++
packages/typescript-estree/package.json | 4 ++--
12 files changed, 61 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ccbbce028b9f..fbde088c3966 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,20 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01)
+
+### Bug Fixes
+
+- **eslint-plugin:** fix no-extraneous-class for class without name ([#174](https://github.com/typescript-eslint/typescript-eslint/issues/174)) ([b1dbb64](https://github.com/typescript-eslint/typescript-eslint/commit/b1dbb64))
+- **eslint-plugin:** fix wrong URL ([#180](https://github.com/typescript-eslint/typescript-eslint/issues/180)) ([00d020d](https://github.com/typescript-eslint/typescript-eslint/commit/00d020d))
+- **eslint-plugin:** use bracket for infer type in array-type rule ([#173](https://github.com/typescript-eslint/typescript-eslint/issues/173)) ([1f868ce](https://github.com/typescript-eslint/typescript-eslint/commit/1f868ce))
+- **parser:** fix regression with no-unused-vars for jsx attributes ([#161](https://github.com/typescript-eslint/typescript-eslint/issues/161)) ([6147de1](https://github.com/typescript-eslint/typescript-eslint/commit/6147de1))
+
+### Features
+
+- **eslint-plugin:** add eslint rule no-useless-constructor ([#167](https://github.com/typescript-eslint/typescript-eslint/issues/167)) ([3fb57a5](https://github.com/typescript-eslint/typescript-eslint/commit/3fb57a5))
+- **eslint-plugin:** add no-unnecessary-type-assertion rule ([#157](https://github.com/typescript-eslint/typescript-eslint/issues/157)) ([38abc28](https://github.com/typescript-eslint/typescript-eslint/commit/38abc28))
+
## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
### Bug Fixes
diff --git a/lerna.json b/lerna.json
index 06bbd031b2c8..77a95bb3fb2c 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
{
- "version": "1.1.1",
+ "version": "1.2.0",
"npmClient": "yarn",
"useWorkspaces": true,
"stream": true
diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md
index 46f2c1960d94..ca4b53781cd3 100644
--- a/packages/eslint-plugin-tslint/CHANGELOG.md
+++ b/packages/eslint-plugin-tslint/CHANGELOG.md
@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01)
+
+**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
+
## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json
index b54084d620e4..59b66dd7b153 100644
--- a/packages/eslint-plugin-tslint/package.json
+++ b/packages/eslint-plugin-tslint/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin-tslint",
- "version": "1.1.1",
+ "version": "1.2.0",
"main": "dist/index.js",
"typings": "src/index.ts",
"description": "TSLint wrapper plugin for ESLint",
@@ -34,6 +34,6 @@
"devDependencies": {
"@types/eslint": "^4.16.3",
"@types/lodash.memoize": "^4.1.4",
- "@typescript-eslint/parser": "1.1.1"
+ "@typescript-eslint/parser": "1.2.0"
}
}
diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md
index 992ae046dde3..6f10e09e6f08 100644
--- a/packages/eslint-plugin/CHANGELOG.md
+++ b/packages/eslint-plugin/CHANGELOG.md
@@ -3,6 +3,20 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01)
+
+### Bug Fixes
+
+- **eslint-plugin:** fix no-extraneous-class for class without name ([#174](https://github.com/typescript-eslint/typescript-eslint/issues/174)) ([b1dbb64](https://github.com/typescript-eslint/typescript-eslint/commit/b1dbb64))
+- **eslint-plugin:** fix wrong URL ([#180](https://github.com/typescript-eslint/typescript-eslint/issues/180)) ([00d020d](https://github.com/typescript-eslint/typescript-eslint/commit/00d020d))
+- **eslint-plugin:** use bracket for infer type in array-type rule ([#173](https://github.com/typescript-eslint/typescript-eslint/issues/173)) ([1f868ce](https://github.com/typescript-eslint/typescript-eslint/commit/1f868ce))
+- **parser:** fix regression with no-unused-vars for jsx attributes ([#161](https://github.com/typescript-eslint/typescript-eslint/issues/161)) ([6147de1](https://github.com/typescript-eslint/typescript-eslint/commit/6147de1))
+
+### Features
+
+- **eslint-plugin:** add eslint rule no-useless-constructor ([#167](https://github.com/typescript-eslint/typescript-eslint/issues/167)) ([3fb57a5](https://github.com/typescript-eslint/typescript-eslint/commit/3fb57a5))
+- **eslint-plugin:** add no-unnecessary-type-assertion rule ([#157](https://github.com/typescript-eslint/typescript-eslint/issues/157)) ([38abc28](https://github.com/typescript-eslint/typescript-eslint/commit/38abc28))
+
## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
### Bug Fixes
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index 350da0cb2aff..b0bf9f288e0e 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin",
- "version": "1.1.1",
+ "version": "1.2.0",
"description": "TypeScript plugin for ESLint",
"keywords": [
"eslint",
@@ -24,7 +24,7 @@
"recommended:update": "node tools/update-recommended.js"
},
"dependencies": {
- "@typescript-eslint/parser": "1.1.1",
+ "@typescript-eslint/parser": "1.2.0",
"requireindex": "^1.2.0",
"tsutils": "^3.7.0"
},
diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md
index f2047e5c6d25..5e618787d914 100644
--- a/packages/parser/CHANGELOG.md
+++ b/packages/parser/CHANGELOG.md
@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01)
+
+### Bug Fixes
+
+- **parser:** fix regression with no-unused-vars for jsx attributes ([#161](https://github.com/typescript-eslint/typescript-eslint/issues/161)) ([6147de1](https://github.com/typescript-eslint/typescript-eslint/commit/6147de1))
+
## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
### Bug Fixes
diff --git a/packages/parser/package.json b/packages/parser/package.json
index 6cf42f6ce6db..26de602491a7 100644
--- a/packages/parser/package.json
+++ b/packages/parser/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/parser",
- "version": "1.1.1",
+ "version": "1.2.0",
"description": "An ESLint custom parser which leverages TypeScript ESTree",
"main": "dist/parser.js",
"files": [
@@ -36,7 +36,7 @@
"typescript": "*"
},
"dependencies": {
- "@typescript-eslint/typescript-estree": "1.1.1",
+ "@typescript-eslint/typescript-estree": "1.2.0",
"eslint-scope": "^4.0.0",
"eslint-visitor-keys": "^1.0.0"
},
@@ -44,6 +44,6 @@
"@types/eslint": "^4.16.5",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/estree": "^0.0.39",
- "@typescript-eslint/shared-fixtures": "1.1.1"
+ "@typescript-eslint/shared-fixtures": "1.2.0"
}
}
diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md
index 2c81f52bfe1e..6ac765de90a1 100644
--- a/packages/shared-fixtures/CHANGELOG.md
+++ b/packages/shared-fixtures/CHANGELOG.md
@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01)
+
+**Note:** Version bump only for package @typescript-eslint/shared-fixtures
+
+
+
+
+
## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
**Note:** Version bump only for package @typescript-eslint/shared-fixtures
diff --git a/packages/shared-fixtures/package.json b/packages/shared-fixtures/package.json
index e5b8b9613aad..99e0091de873 100644
--- a/packages/shared-fixtures/package.json
+++ b/packages/shared-fixtures/package.json
@@ -1,5 +1,5 @@
{
"name": "@typescript-eslint/shared-fixtures",
- "version": "1.1.1",
+ "version": "1.2.0",
"private": true
}
diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md
index 2fcfd25aae42..a1fc5f4167ef 100644
--- a/packages/typescript-estree/CHANGELOG.md
+++ b/packages/typescript-estree/CHANGELOG.md
@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+# [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01)
+
+**Note:** Version bump only for package @typescript-eslint/typescript-estree
+
## [1.1.1](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.0...v1.1.1) (2019-01-29)
### Bug Fixes
diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json
index 2be4fceecffc..5c7f52edf274 100644
--- a/packages/typescript-estree/package.json
+++ b/packages/typescript-estree/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/typescript-estree",
- "version": "1.1.1",
+ "version": "1.2.0",
"description": "A parser that converts TypeScript source code into an ESTree compatible form",
"main": "dist/parser.js",
"types": "dist/parser.d.ts",
@@ -42,7 +42,7 @@
"typescript": "*"
},
"devDependencies": {
- "@typescript-eslint/shared-fixtures": "1.1.1",
+ "@typescript-eslint/shared-fixtures": "1.2.0",
"typescript": "~3.2.1"
}
}
From 3efb265ea85406f8700cca1c40a87f5c30b1452b Mon Sep 17 00:00:00 2001
From: Armano
Date: Sat, 2 Feb 2019 15:35:59 +0100
Subject: [PATCH 60/88] test(ts-estree): add regression test for decorators on
variables (#186)
---
.../lib/__snapshots__/typescript.ts.snap | 244 ++++++++++++++++++
.../decorator-on-variable.src.ts | 2 +
.../semantic-diagnostics-enabled.ts.snap | 9 +
.../lib/__snapshots__/typescript.ts.snap | 243 +++++++++++++++++
4 files changed, 498 insertions(+)
create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-variable.src.ts
diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
index f540948a5558..f57d7523a358 100644
--- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap
@@ -89541,6 +89541,250 @@ Object {
}
`;
+exports[`typescript fixtures/errorRecovery/decorator-on-variable.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declarations": Array [
+ Object {
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "name": "a",
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ },
+ "init": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "raw": "1",
+ "type": "Literal",
+ "value": 1,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 14,
+ 19,
+ ],
+ "type": "VariableDeclarator",
+ },
+ ],
+ "kind": "const",
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 19,
+ ],
+ "type": "VariableDeclaration",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 20,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 1,
+ ],
+ "type": "Punctuator",
+ "value": "@",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 1,
+ 5,
+ ],
+ "type": "Identifier",
+ "value": "deco",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 5,
+ 6,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 8,
+ 13,
+ ],
+ "type": "Keyword",
+ "value": "const",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ "value": "a",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 16,
+ 17,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "type": "Numeric",
+ "value": "1",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`typescript fixtures/errorRecovery/empty-type-arguments.src 1`] = `
Object {
"body": Array [
diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-variable.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-variable.src.ts
new file mode 100644
index 000000000000..700dea545cce
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-variable.src.ts
@@ -0,0 +1,2 @@
+@deco()
+const a = 1
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
index 1db62d5b9140..a0cc4cb96444 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
@@ -2299,6 +2299,15 @@ Object {
}
`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/decorator-on-variable.src 1`] = `
+Object {
+ "column": 0,
+ "index": 0,
+ "lineNumber": 1,
+ "message": "Decorators are not valid here.",
+}
+`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/enum-with-keywords.src 1`] = `
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
index b807e63a8220..0c1e0c5afe60 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap
@@ -88851,6 +88851,249 @@ Object {
}
`;
+exports[`typescript fixtures/errorRecovery/decorator-on-variable.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "declarations": Array [
+ Object {
+ "id": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "name": "a",
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ },
+ "init": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "raw": "1",
+ "type": "Literal",
+ "value": 1,
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 14,
+ 19,
+ ],
+ "type": "VariableDeclarator",
+ },
+ ],
+ "kind": "const",
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 19,
+ ],
+ "type": "VariableDeclaration",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 20,
+ ],
+ "sourceType": "script",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 1,
+ ],
+ "type": "Punctuator",
+ "value": "@",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 1,
+ 5,
+ ],
+ "type": "Identifier",
+ "value": "deco",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 5,
+ 6,
+ ],
+ "type": "Punctuator",
+ "value": "(",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Punctuator",
+ "value": ")",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 8,
+ 13,
+ ],
+ "type": "Keyword",
+ "value": "const",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 14,
+ 15,
+ ],
+ "type": "Identifier",
+ "value": "a",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 16,
+ 17,
+ ],
+ "type": "Punctuator",
+ "value": "=",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 18,
+ 19,
+ ],
+ "type": "Numeric",
+ "value": "1",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`typescript fixtures/errorRecovery/empty-type-arguments.src 1`] = `
Object {
"body": Array [
From 3b0fed6674e84523ef84005229e9e271a65d6e23 Mon Sep 17 00:00:00 2001
From: Kanitkorn Sujautra
Date: Sun, 3 Feb 2019 21:57:23 +0900
Subject: [PATCH 61/88] docs(eslint-plugin): fix rule URLs still point to the
old repository (#189)
* docs(eslint-plugin): update rule url to the new repo
Fix https://github.com/typescript-eslint/typescript-eslint/issues/188
* docs(eslint-plugin): add a link for no-unnecessary-type-assertion rule
---
packages/eslint-plugin/ROADMAP.md | 57 ++++++++++++++++---------------
1 file changed, 29 insertions(+), 28 deletions(-)
diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md
index 378a3140ffb8..48e0696eea9c 100644
--- a/packages/eslint-plugin/ROADMAP.md
+++ b/packages/eslint-plugin/ROADMAP.md
@@ -557,34 +557,35 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint-
-[`@typescript-eslint/adjacent-overload-signatures`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/adjacent-overload-signatures.md
-[`@typescript-eslint/ban-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/ban-types.md
-[`@typescript-eslint/explicit-member-accessibility`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/explicit-member-accessibility.md
-[`@typescript-eslint/member-ordering`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-ordering.md
-[`@typescript-eslint/no-explicit-any`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-explicit-any.md
-[`@typescript-eslint/no-empty-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-empty-interface.md
-[`@typescript-eslint/no-inferrable-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-inferrable-types.md
-[`@typescript-eslint/prefer-namespace-keyword`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-namespace-keyword.md
-[`@typescript-eslint/no-namespace`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-namespace.md
-[`@typescript-eslint/no-non-null-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-non-null-assertion.md
-[`@typescript-eslint/no-triple-slash-reference`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-triple-slash-reference.md
-[`@typescript-eslint/no-var-requires`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-var-requires.md
-[`@typescript-eslint/type-annotation-spacing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/type-annotation-spacing.md
-[`@typescript-eslint/no-misused-new`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-misused-new.md
-[`@typescript-eslint/no-object-literal-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-object-literal-type-assertion.md
-[`@typescript-eslint/no-this-alias`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-this-alias.md
-[`@typescript-eslint/no-extraneous-class`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-extraneous-class.md
-[`@typescript-eslint/no-unused-vars`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-unused-vars.md
-[`@typescript-eslint/no-use-before-define`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-use-before-define.md
-[`@typescript-eslint/indent`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/indent.md
-[`@typescript-eslint/array-type`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/array-type.md
-[`@typescript-eslint/class-name-casing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/class-name-casing.md
-[`@typescript-eslint/interface-name-prefix`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/interface-name-prefix.md
-[`@typescript-eslint/no-angle-bracket-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-angle-bracket-type-assertion.md
-[`@typescript-eslint/no-parameter-properties`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-parameter-properties.md
-[`@typescript-eslint/member-delimiter-style`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-delimiter-style.md
-[`@typescript-eslint/prefer-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-interface.md
-[`@typescript-eslint/no-array-constructor`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-array-constructor.md
+[`@typescript-eslint/adjacent-overload-signatures`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md
+[`@typescript-eslint/ban-types`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md
+[`@typescript-eslint/explicit-member-accessibility`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md
+[`@typescript-eslint/member-ordering`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-ordering.md
+[`@typescript-eslint/no-explicit-any`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-explicit-any.md
+[`@typescript-eslint/no-empty-interface`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-interface.md
+[`@typescript-eslint/no-inferrable-types`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-inferrable-types.md
+[`@typescript-eslint/prefer-namespace-keyword`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md
+[`@typescript-eslint/no-namespace`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-namespace.md
+[`@typescript-eslint/no-non-null-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-non-null-assertion.md
+[`@typescript-eslint/no-triple-slash-reference`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-triple-slash-reference.md
+[`@typescript-eslint/no-unnecessary-type-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md
+[`@typescript-eslint/no-var-requires`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-var-requires.md
+[`@typescript-eslint/type-annotation-spacing`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/type-annotation-spacing.md
+[`@typescript-eslint/no-misused-new`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-misused-new.md
+[`@typescript-eslint/no-object-literal-type-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-object-literal-type-assertion.md
+[`@typescript-eslint/no-this-alias`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-this-alias.md
+[`@typescript-eslint/no-extraneous-class`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extraneous-class.md
+[`@typescript-eslint/no-unused-vars`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
+[`@typescript-eslint/no-use-before-define`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md
+[`@typescript-eslint/indent`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md
+[`@typescript-eslint/array-type`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
+[`@typescript-eslint/class-name-casing`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/class-name-casing.md
+[`@typescript-eslint/interface-name-prefix`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/interface-name-prefix.md
+[`@typescript-eslint/no-angle-bracket-type-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-angle-bracket-type-assertion.md
+[`@typescript-eslint/no-parameter-properties`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-parameter-properties.md
+[`@typescript-eslint/member-delimiter-style`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md
+[`@typescript-eslint/prefer-interface`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-interface.md
+[`@typescript-eslint/no-array-constructor`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-array-constructor.md
From f03ed0765fd93539a5aef71ddd66fde8d92f1ce3 Mon Sep 17 00:00:00 2001
From: Armano
Date: Sun, 3 Feb 2019 17:09:48 +0100
Subject: [PATCH 62/88] docs(eslint-plugin): replace whitespaces with tag
(#198)
---
packages/eslint-plugin/ROADMAP.md | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md
index 48e0696eea9c..f26d0e80175c 100644
--- a/packages/eslint-plugin/ROADMAP.md
+++ b/packages/eslint-plugin/ROADMAP.md
@@ -1,9 +1,9 @@
# Roadmap
-✅ (28) = done
-🌟 (79) = in ESLint core
-🔌 (33) = in another plugin
-🌓 (16) = implementations differ or ESLint version is missing functionality
+✅ (28) = done
+🌟 (79) = in ESLint core
+🔌 (33) = in another plugin
+🌓 (16) = implementations differ or ESLint version is missing functionality
🛑 (70) = unimplemented
## TSLint rules
@@ -96,7 +96,7 @@
| [`use-default-type-parameter`] | 🛑 | N/A |
| [`use-isnan`] | 🌟 | [`use-isnan`][use-isnan] |
-[1] The ESLint rule also supports silencing with an extra set of parens (`if ((foo = bar)) {}`)
+[1] The ESLint rule also supports silencing with an extra set of parens (`if ((foo = bar)) {}`)
[2] Missing private class member support. [`@typescript-eslint/no-unused-vars`] adds support for some TS-specific features.
### Maintainability
@@ -120,7 +120,7 @@
| [`prefer-readonly`] | 🛑 | N/A |
| [`trailing-comma`] | 🌓 | [`comma-dangle`][comma-dangle] or [Prettier] |
-[1] Only warns when importing deprecated symbols
+[1] Only warns when importing deprecated symbols
[2] Missing support for blank-line-delimited sections
### Style
@@ -179,7 +179,7 @@
| [`variable-name`] | 🌟 | [2] |
| [`whitespace`] | 🔌 | Use [Prettier] |
-[1] Recommended config: `["error", { blankLine: "always", prev: "*", next: "return" }]`
+[1] Recommended config: `["error", { blankLine: "always", prev: "*", next: "return" }]`
[2] [`camelcase`][camelcase], [`no-underscore-dangle`][no-underscore-dangle], [`id-blacklist`][id-blacklist], and/or [`id-match`][id-match]
## tslint-microsoft-contrib rules
@@ -245,10 +245,10 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint-
| `use-named-parameter` | 🛑 | N/A |
| `use-simple-attributes` | 🛑 | N/A |
-[1] Enforces blank lines both at the beginning and end of a block
-[2] Recommended config: `["error", "ForInStatement"]`
-[3] Recommended config: `["error", "declaration", { "allowArrowFunctions": true }]`
-[4] Recommended config: `["error", { "terms": ["BUG", "HACK", "FIXME", "LATER", "LATER2", "TODO"], "location": "anywhere" }]`
+[1] Enforces blank lines both at the beginning and end of a block
+[2] Recommended config: `["error", "ForInStatement"]`
+[3] Recommended config: `["error", "declaration", { "allowArrowFunctions": true }]`
+[4] Recommended config: `["error", { "terms": ["BUG", "HACK", "FIXME", "LATER", "LATER2", "TODO"], "location": "anywhere" }]`
[5] Does not check class fields.
[insecure-random]: https://github.com/desktop/desktop/blob/master/eslint-rules/insecure-random.js
@@ -310,7 +310,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint-
| `react-a11y-titles` | 🛑 | N/A |
| `react-anchor-blank-noopener` | 🛑 | N/A |
-[1] TSLint rule is more strict
+[1] TSLint rule is more strict
[2] ESLint rule only reports for click handlers
[prettier]: https://prettier.io
From f35c20b100dfa516d695000f6cdc38b6fd5248a2 Mon Sep 17 00:00:00 2001
From: Josh Goldberg
Date: Sun, 3 Feb 2019 11:10:41 -0500
Subject: [PATCH 63/88] chore: removed unnecessary path prefix from
.vscode/launch.json (#196)
---
.vscode/launch.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 18bf27ada556..4ac7bc13cdd0 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -12,7 +12,7 @@
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
"args": [
"--colors",
- "${workspaceFolder}/packages/eslint-plugin/tests/lib/rules/${fileBasename}"
+ "tests/lib/rules/${fileBasename}"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
From f856e76629e4f737a727c53cfd58f7561e490579 Mon Sep 17 00:00:00 2001
From: Armano
Date: Sun, 3 Feb 2019 19:23:40 +0100
Subject: [PATCH 64/88] test(*): update eslint-plugin-jest and enable
recommended rules (#190)
---
.eslintrc.json | 15 +++++++++++----
package.json | 2 +-
packages/parser/tests/lib/parser.ts | 2 +-
packages/typescript-estree/tests/lib/parse.ts | 6 +++---
.../typescript-estree/tests/lib/semanticInfo.ts | 4 ++--
.../tests/lib/warn-on-unsupported-ts.ts | 2 +-
yarn.lock | 8 ++++----
7 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/.eslintrc.json b/.eslintrc.json
index f44790c843c8..40a5182652ad 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -29,10 +29,10 @@
"overrides": [
{
"files": [
- "packages/eslint-plugin-tslint/**/*.ts",
- "packages/eslint-plugin/**/*.js",
- "packages/parser/**/*.ts",
- "packages/typescript-estree/**/*.ts"
+ "packages/eslint-plugin-tslint/tests/**/*.ts",
+ "packages/eslint-plugin/tests/**/*.js",
+ "packages/parser/tests/**/*.ts",
+ "packages/typescript-estree/tests/**/*.ts"
],
"env": {
"jest/globals": true
@@ -40,8 +40,15 @@
"rules": {
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
+ "jest/no-alias-methods": "error",
"jest/no-identical-title": "error",
+ "jest/no-jasmine-globals": "error",
+ "jest/no-jest-import": "error",
+ "jest/no-test-prefixes": "error",
+ "jest/no-test-callback": "error",
+ "jest/no-test-return-statement": "error",
"jest/prefer-to-have-length": "warn",
+ "jest/prefer-spy-on": "error",
"jest/valid-expect": "error"
}
},
diff --git a/package.json b/package.json
index 18059f7381ed..a95c4a1a5710 100644
--- a/package.json
+++ b/package.json
@@ -58,7 +58,7 @@
"cz-conventional-changelog": "2.1.0",
"eslint": "^5.12.1",
"eslint-plugin-eslint-plugin": "^2.0.1",
- "eslint-plugin-jest": "^22.1.3",
+ "eslint-plugin-jest": "^22.2.2",
"glob": "7.1.2",
"husky": "^1.3.1",
"jest": "23.6.0",
diff --git a/packages/parser/tests/lib/parser.ts b/packages/parser/tests/lib/parser.ts
index bfc23bac5abb..332be8b6e43c 100644
--- a/packages/parser/tests/lib/parser.ts
+++ b/packages/parser/tests/lib/parser.ts
@@ -24,7 +24,7 @@ describe('parser', () => {
sourceType: 'script',
useJSXTextNode: true
});
- expect(spyScope).toHaveBeenCalledWith(jasmine.any(Object), {
+ expect(spyScope).toHaveBeenCalledWith(expect.any(Object), {
ecmaFeatures: {},
sourceType: 'script'
});
diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts
index fc7e8af99a10..6bed7ce8bcef 100644
--- a/packages/typescript-estree/tests/lib/parse.ts
+++ b/packages/typescript-estree/tests/lib/parse.ts
@@ -82,7 +82,7 @@ describe('parse()', () => {
});
expect(spy).toHaveBeenCalledWith(
- jasmine.any(Object),
+ expect.any(Object),
{
code: 'let foo = bar;',
comment: true,
@@ -96,8 +96,8 @@ describe('parse()', () => {
projects: [],
range: true,
strict: false,
- tokens: jasmine.any(Array),
- tsconfigRootDir: jasmine.any(String),
+ tokens: expect.any(Array),
+ tsconfigRootDir: expect.any(String),
useJSXTextNode: false
},
false
diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts
index e45cae843ed5..f5612f191cc5 100644
--- a/packages/typescript-estree/tests/lib/semanticInfo.ts
+++ b/packages/typescript-estree/tests/lib/semanticInfo.ts
@@ -179,7 +179,7 @@ describe('semanticInfo', () => {
badConfig.project = './tsconfigs.json';
expect(() =>
parseCodeAndGenerateServices(readFileSync(fileName, 'utf8'), badConfig)
- ).toThrowError(/File .+tsconfigs\.json' not found/);
+ ).toThrow(/File .+tsconfigs\.json' not found/);
});
it('fail to read project file', () => {
@@ -188,7 +188,7 @@ describe('semanticInfo', () => {
badConfig.project = '.';
expect(() =>
parseCodeAndGenerateServices(readFileSync(fileName, 'utf8'), badConfig)
- ).toThrowError(/File .+semanticInfo' not found/);
+ ).toThrow(/File .+semanticInfo' not found/);
});
it('malformed project file', () => {
diff --git a/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts
index d984007bf757..565b997c35fc 100644
--- a/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts
+++ b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts
@@ -11,7 +11,7 @@ describe('Warn on unsupported TypeScript version', () => {
it('should warn the user if they are using an unsupported TypeScript version', () => {
(semver.satisfies as jest.Mock).mockReturnValue(false);
- console.log = jest.fn();
+ jest.spyOn(console, 'log').mockImplementation();
parser.parse('');
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(
diff --git a/yarn.lock b/yarn.lock
index 6980f52cafb8..1969160e6c41 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2378,10 +2378,10 @@ eslint-plugin-eslint-plugin@^2.0.1:
resolved "https://registry.yarnpkg.com/eslint-plugin-eslint-plugin/-/eslint-plugin-eslint-plugin-2.0.1.tgz#d275434969dbde3da1d4cb7a121dc8d88457c786"
integrity sha512-kJ5TZsRJH/xYstG07v3YeOy/W5SDAEzV+bvvoL0aiG1HtqDmg4mJvNPnn/JngANMmsx8oXlJrIcBTCpJzm+9kg==
-eslint-plugin-jest@^22.1.3:
- version "22.1.3"
- resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.1.3.tgz#4444108dfcddc5d2117ed6dc551f529d7e73a99e"
- integrity sha512-JTZTI6WQoNruAugNyCO8fXfTONVcDd5i6dMRFA5g3rUFn1UDDLILY1bTL6alvNXbW2U7Sc2OSpi8m08pInnq0A==
+eslint-plugin-jest@^22.2.2:
+ version "22.2.2"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.2.2.tgz#2a80d70a20c27dfb1503a6f32cdcb647fe5476df"
+ integrity sha512-hnWgh9o39VJfz6lJEyQJdTW7dN2yynlGkmPOlU/oMHh+d7WVMsJP1GeDTB520VCDljEdKExCwD5IBpQIUl4mJg==
eslint-scope@^4.0.0:
version "4.0.0"
From a36e727277d9815cfdd6f0b67e0981d84035698f Mon Sep 17 00:00:00 2001
From: Armano
Date: Sun, 3 Feb 2019 19:40:26 +0100
Subject: [PATCH 65/88] test(ts-estree): add test for parsing nested jsx tag
names (#191)
---
.../tests/lib/__snapshots__/jsx.ts.snap | 1716 +++++++++++++++++
.../tag-names-with-multi-dots-multi.src.js | 3 +
.../tests/ast-alignment/fixtures-to-test.ts | 7 +-
.../tests/lib/__snapshots__/jsx.ts.snap | 1715 ++++++++++++++++
.../semantic-diagnostics-enabled.ts.snap | 9 +
5 files changed, 3449 insertions(+), 1 deletion(-)
create mode 100644 packages/shared-fixtures/fixtures/jsx/tag-names-with-multi-dots-multi.src.js
diff --git a/packages/parser/tests/lib/__snapshots__/jsx.ts.snap b/packages/parser/tests/lib/__snapshots__/jsx.ts.snap
index 8a6365ac56b6..02d917e3fb56 100644
--- a/packages/parser/tests/lib/__snapshots__/jsx.ts.snap
+++ b/packages/parser/tests/lib/__snapshots__/jsx.ts.snap
@@ -9463,6 +9463,1722 @@ Object {
}
`;
+exports[`JSX useJSXTextNode: false fixtures/tag-names-with-multi-dots-multi.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "expression": Object {
+ "children": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 16,
+ ],
+ "raw": "
+ ",
+ "type": "Literal",
+ "value": "
+ ",
+ },
+ Object {
+ "children": Array [],
+ "closingElement": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 57,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 29,
+ "line": 2,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 56,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 41,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 35,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 45,
+ 49,
+ ],
+ "type": "ThisExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 41,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 36,
+ "line": 2,
+ },
+ },
+ "name": "const",
+ "range": Array [
+ 50,
+ 55,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 45,
+ 55,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 42,
+ "line": 2,
+ },
+ },
+ "name": "declare",
+ "range": Array [
+ 56,
+ 63,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 45,
+ 63,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 56,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 50,
+ "line": 2,
+ },
+ },
+ "name": "static",
+ "range": Array [
+ 64,
+ 70,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 45,
+ 70,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "range": Array [
+ 43,
+ 71,
+ ],
+ "type": "JSXClosingElement",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 57,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "openingElement": Object {
+ "attributes": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 29,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 17,
+ 21,
+ ],
+ "type": "ThisExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 2,
+ },
+ },
+ "name": "const",
+ "range": Array [
+ 22,
+ 27,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 17,
+ 27,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 2,
+ },
+ },
+ "name": "declare",
+ "range": Array [
+ 28,
+ 35,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 17,
+ 35,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 2,
+ },
+ },
+ "name": "static",
+ "range": Array [
+ 36,
+ 42,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 17,
+ 42,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "range": Array [
+ 16,
+ 43,
+ ],
+ "selfClosing": false,
+ "type": "JSXOpeningElement",
+ },
+ "range": Array [
+ 16,
+ 71,
+ ],
+ "type": "JSXElement",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 57,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 71,
+ 72,
+ ],
+ "raw": "
+",
+ "type": "Literal",
+ "value": "
+",
+ },
+ ],
+ "closingElement": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "name": "a",
+ "range": Array [
+ 74,
+ 75,
+ ],
+ "type": "Identifier",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "name": "b",
+ "range": Array [
+ 76,
+ 77,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 74,
+ 77,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 3,
+ },
+ },
+ "name": "c",
+ "range": Array [
+ 78,
+ 79,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 74,
+ 79,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 3,
+ },
+ },
+ "name": "d",
+ "range": Array [
+ 80,
+ 81,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 74,
+ 81,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 3,
+ },
+ },
+ "name": "e",
+ "range": Array [
+ 82,
+ 83,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 74,
+ 83,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 12,
+ "line": 3,
+ },
+ },
+ "name": "f",
+ "range": Array [
+ 84,
+ 85,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 74,
+ 85,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "range": Array [
+ 72,
+ 86,
+ ],
+ "type": "JSXClosingElement",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "openingElement": Object {
+ "attributes": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "name": "a",
+ "range": Array [
+ 1,
+ 2,
+ ],
+ "type": "Identifier",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 1,
+ },
+ },
+ "name": "b",
+ "range": Array [
+ 3,
+ 4,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 1,
+ 4,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 1,
+ },
+ },
+ "name": "c",
+ "range": Array [
+ 5,
+ 6,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 1,
+ 6,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "name": "d",
+ "range": Array [
+ 7,
+ 8,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 1,
+ 8,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "name": "e",
+ "range": Array [
+ 9,
+ 10,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 1,
+ 10,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "name": "f",
+ "range": Array [
+ 11,
+ 12,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 1,
+ 12,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "range": Array [
+ 0,
+ 13,
+ ],
+ "selfClosing": false,
+ "type": "JSXOpeningElement",
+ },
+ "range": Array [
+ 0,
+ 86,
+ ],
+ "type": "JSXElement",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 87,
+ ],
+ "type": "ExpressionStatement",
+ },
+ ],
+ "comments": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 88,
+ ],
+ "sourceType": "module",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 1,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 1,
+ 2,
+ ],
+ "type": "JSXIdentifier",
+ "value": "a",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 2,
+ 3,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 3,
+ 4,
+ ],
+ "type": "JSXIdentifier",
+ "value": "b",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 4,
+ 5,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 5,
+ 6,
+ ],
+ "type": "JSXIdentifier",
+ "value": "c",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 8,
+ ],
+ "type": "JSXIdentifier",
+ "value": "d",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 8,
+ 9,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 9,
+ 10,
+ ],
+ "type": "JSXIdentifier",
+ "value": "e",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 10,
+ 11,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 11,
+ 12,
+ ],
+ "type": "JSXIdentifier",
+ "value": "f",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 12,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 12,
+ 13,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 16,
+ ],
+ "type": "JSXText",
+ "value": "
+ ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 16,
+ 17,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 17,
+ 21,
+ ],
+ "type": "Keyword",
+ "value": "this",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 21,
+ 22,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 22,
+ 27,
+ ],
+ "type": "Keyword",
+ "value": "const",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 28,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 28,
+ 35,
+ ],
+ "type": "Keyword",
+ "value": "declare",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 22,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 21,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 35,
+ 36,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 36,
+ 42,
+ ],
+ "type": "Keyword",
+ "value": "static",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 29,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 28,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 42,
+ 43,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 29,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 43,
+ 44,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 31,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 30,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 44,
+ 45,
+ ],
+ "type": "Punctuator",
+ "value": "/",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 35,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 45,
+ 49,
+ ],
+ "type": "Keyword",
+ "value": "this",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 36,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 35,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 49,
+ 50,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 41,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 36,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 50,
+ 55,
+ ],
+ "type": "Keyword",
+ "value": "const",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 41,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 55,
+ 56,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 42,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 56,
+ 63,
+ ],
+ "type": "Keyword",
+ "value": "declare",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 50,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 49,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 63,
+ 64,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 56,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 50,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 64,
+ 70,
+ ],
+ "type": "Keyword",
+ "value": "static",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 57,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 56,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 70,
+ 71,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 57,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 71,
+ 72,
+ ],
+ "type": "JSXText",
+ "value": "
+",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 72,
+ 73,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 73,
+ 74,
+ ],
+ "type": "Punctuator",
+ "value": "/",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 74,
+ 75,
+ ],
+ "type": "JSXIdentifier",
+ "value": "a",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 75,
+ 76,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 76,
+ 77,
+ ],
+ "type": "JSXIdentifier",
+ "value": "b",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 77,
+ 78,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 78,
+ 79,
+ ],
+ "type": "JSXIdentifier",
+ "value": "c",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 79,
+ 80,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 80,
+ 81,
+ ],
+ "type": "JSXIdentifier",
+ "value": "d",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 81,
+ 82,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 82,
+ 83,
+ ],
+ "type": "JSXIdentifier",
+ "value": "e",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 83,
+ 84,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 12,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 84,
+ 85,
+ ],
+ "type": "JSXIdentifier",
+ "value": "f",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 85,
+ 86,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 86,
+ 87,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`JSX useJSXTextNode: false fixtures/test-content.src 1`] = `
Object {
"body": Array [
diff --git a/packages/shared-fixtures/fixtures/jsx/tag-names-with-multi-dots-multi.src.js b/packages/shared-fixtures/fixtures/jsx/tag-names-with-multi-dots-multi.src.js
new file mode 100644
index 000000000000..1599e0620cd9
--- /dev/null
+++ b/packages/shared-fixtures/fixtures/jsx/tag-names-with-multi-dots-multi.src.js
@@ -0,0 +1,3 @@
+
+
+ ;
diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
index e92f68f968f4..ede45e93fcda 100644
--- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
+++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
@@ -284,7 +284,12 @@ tester.addFixturePatternConfig('javascript/unicodeCodePointEscapes');
/* ================================================== */
tester.addFixturePatternConfig('jsx', {
- ignore: jsxFilesWithKnownIssues
+ ignore: jsxFilesWithKnownIssues.concat([
+ /**
+ * ts-estree: nested jsx tag names are not correctly converted
+ */
+ 'tag-names-with-multi-dots-multi'
+ ])
});
tester.addFixturePatternConfig('jsx-useJSXTextNode');
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap
index 1da61ddcac7e..cb1f698c267c 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap
@@ -9423,6 +9423,1721 @@ Object {
}
`;
+exports[`JSX useJSXTextNode: false fixtures/tag-names-with-multi-dots-multi.src 1`] = `
+Object {
+ "body": Array [
+ Object {
+ "expression": Object {
+ "children": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 16,
+ ],
+ "raw": "
+ ",
+ "type": "Literal",
+ "value": "
+ ",
+ },
+ Object {
+ "children": Array [],
+ "closingElement": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 57,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 29,
+ "line": 2,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 56,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 41,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 35,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 45,
+ 49,
+ ],
+ "type": "ThisExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 41,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 36,
+ "line": 2,
+ },
+ },
+ "name": "const",
+ "range": Array [
+ 50,
+ 55,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 45,
+ 55,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 42,
+ "line": 2,
+ },
+ },
+ "name": "declare",
+ "range": Array [
+ 56,
+ 63,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 45,
+ 63,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 56,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 50,
+ "line": 2,
+ },
+ },
+ "name": "static",
+ "range": Array [
+ 64,
+ 70,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 45,
+ 70,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "range": Array [
+ 43,
+ 71,
+ ],
+ "type": "JSXClosingElement",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 57,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "openingElement": Object {
+ "attributes": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 29,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 17,
+ 21,
+ ],
+ "type": "ThisExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 2,
+ },
+ },
+ "name": "const",
+ "range": Array [
+ 22,
+ 27,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 17,
+ 27,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 2,
+ },
+ },
+ "name": "declare",
+ "range": Array [
+ 28,
+ 35,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 17,
+ 35,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 2,
+ },
+ },
+ "name": "static",
+ "range": Array [
+ 36,
+ 42,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 17,
+ 42,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "range": Array [
+ 16,
+ 43,
+ ],
+ "selfClosing": false,
+ "type": "JSXOpeningElement",
+ },
+ "range": Array [
+ 16,
+ 71,
+ ],
+ "type": "JSXElement",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 57,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 71,
+ 72,
+ ],
+ "raw": "
+",
+ "type": "Literal",
+ "value": "
+",
+ },
+ ],
+ "closingElement": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "name": "a",
+ "range": Array [
+ 74,
+ 75,
+ ],
+ "type": "Identifier",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "name": "b",
+ "range": Array [
+ 76,
+ 77,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 74,
+ 77,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 3,
+ },
+ },
+ "name": "c",
+ "range": Array [
+ 78,
+ 79,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 74,
+ 79,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 3,
+ },
+ },
+ "name": "d",
+ "range": Array [
+ 80,
+ 81,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 74,
+ 81,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 3,
+ },
+ },
+ "name": "e",
+ "range": Array [
+ 82,
+ 83,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 74,
+ 83,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 12,
+ "line": 3,
+ },
+ },
+ "name": "f",
+ "range": Array [
+ 84,
+ 85,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 74,
+ 85,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "range": Array [
+ 72,
+ 86,
+ ],
+ "type": "JSXClosingElement",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "openingElement": Object {
+ "attributes": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "name": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "computed": false,
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "object": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "name": "a",
+ "range": Array [
+ 1,
+ 2,
+ ],
+ "type": "Identifier",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 1,
+ },
+ },
+ "name": "b",
+ "range": Array [
+ 3,
+ 4,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 1,
+ 4,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 1,
+ },
+ },
+ "name": "c",
+ "range": Array [
+ 5,
+ 6,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 1,
+ 6,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "name": "d",
+ "range": Array [
+ 7,
+ 8,
+ ],
+ "type": "Identifier",
+ },
+ "range": Array [
+ 1,
+ 8,
+ ],
+ "type": "MemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "name": "e",
+ "range": Array [
+ 9,
+ 10,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 1,
+ 10,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "property": Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "name": "f",
+ "range": Array [
+ 11,
+ 12,
+ ],
+ "type": "JSXIdentifier",
+ },
+ "range": Array [
+ 1,
+ 12,
+ ],
+ "type": "JSXMemberExpression",
+ },
+ "range": Array [
+ 0,
+ 13,
+ ],
+ "selfClosing": false,
+ "type": "JSXOpeningElement",
+ },
+ "range": Array [
+ 0,
+ 86,
+ ],
+ "type": "JSXElement",
+ },
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 87,
+ ],
+ "type": "ExpressionStatement",
+ },
+ ],
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 4,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 88,
+ ],
+ "sourceType": "script",
+ "tokens": Array [
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 0,
+ 1,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 1,
+ 2,
+ ],
+ "type": "JSXIdentifier",
+ "value": "a",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 2,
+ 3,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 3,
+ 4,
+ ],
+ "type": "JSXIdentifier",
+ "value": "b",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 4,
+ 5,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 5,
+ 6,
+ ],
+ "type": "JSXIdentifier",
+ "value": "c",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 6,
+ 7,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 7,
+ 8,
+ ],
+ "type": "JSXIdentifier",
+ "value": "d",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 8,
+ 9,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 9,
+ 10,
+ ],
+ "type": "JSXIdentifier",
+ "value": "e",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 10,
+ 11,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 11,
+ 12,
+ ],
+ "type": "JSXIdentifier",
+ "value": "f",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 1,
+ },
+ "start": Object {
+ "column": 12,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 12,
+ 13,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 1,
+ },
+ },
+ "range": Array [
+ 13,
+ 16,
+ ],
+ "type": "JSXText",
+ "value": "
+ ",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 16,
+ 17,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 17,
+ 21,
+ ],
+ "type": "Keyword",
+ "value": "this",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 21,
+ 22,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 22,
+ 27,
+ ],
+ "type": "Keyword",
+ "value": "const",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 27,
+ 28,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 21,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 28,
+ 35,
+ ],
+ "type": "Keyword",
+ "value": "declare",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 22,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 21,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 35,
+ 36,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 22,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 36,
+ 42,
+ ],
+ "type": "Keyword",
+ "value": "static",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 29,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 28,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 42,
+ 43,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 30,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 29,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 43,
+ 44,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 31,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 30,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 44,
+ 45,
+ ],
+ "type": "Punctuator",
+ "value": "/",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 35,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 31,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 45,
+ 49,
+ ],
+ "type": "Keyword",
+ "value": "this",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 36,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 35,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 49,
+ 50,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 41,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 36,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 50,
+ 55,
+ ],
+ "type": "Keyword",
+ "value": "const",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 42,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 41,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 55,
+ 56,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 49,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 42,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 56,
+ 63,
+ ],
+ "type": "Keyword",
+ "value": "declare",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 50,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 49,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 63,
+ 64,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 56,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 50,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 64,
+ 70,
+ ],
+ "type": "Keyword",
+ "value": "static",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 57,
+ "line": 2,
+ },
+ "start": Object {
+ "column": 56,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 70,
+ 71,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 0,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 57,
+ "line": 2,
+ },
+ },
+ "range": Array [
+ 71,
+ 72,
+ ],
+ "type": "JSXText",
+ "value": "
+",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 1,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 0,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 72,
+ 73,
+ ],
+ "type": "Punctuator",
+ "value": "<",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 2,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 1,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 73,
+ 74,
+ ],
+ "type": "Punctuator",
+ "value": "/",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 3,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 2,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 74,
+ 75,
+ ],
+ "type": "JSXIdentifier",
+ "value": "a",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 4,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 3,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 75,
+ 76,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 5,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 4,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 76,
+ 77,
+ ],
+ "type": "JSXIdentifier",
+ "value": "b",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 6,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 5,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 77,
+ 78,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 7,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 6,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 78,
+ 79,
+ ],
+ "type": "JSXIdentifier",
+ "value": "c",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 8,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 7,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 79,
+ 80,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 9,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 8,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 80,
+ 81,
+ ],
+ "type": "JSXIdentifier",
+ "value": "d",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 10,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 9,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 81,
+ 82,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 10,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 82,
+ 83,
+ ],
+ "type": "JSXIdentifier",
+ "value": "e",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 12,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 11,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 83,
+ 84,
+ ],
+ "type": "Punctuator",
+ "value": ".",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 13,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 12,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 84,
+ 85,
+ ],
+ "type": "JSXIdentifier",
+ "value": "f",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 14,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 13,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 85,
+ 86,
+ ],
+ "type": "Punctuator",
+ "value": ">",
+ },
+ Object {
+ "loc": Object {
+ "end": Object {
+ "column": 15,
+ "line": 3,
+ },
+ "start": Object {
+ "column": 14,
+ "line": 3,
+ },
+ },
+ "range": Array [
+ 86,
+ 87,
+ ],
+ "type": "Punctuator",
+ "value": ";",
+ },
+ ],
+ "type": "Program",
+}
+`;
+
exports[`JSX useJSXTextNode: false fixtures/test-content.src 1`] = `
Object {
"body": Array [
diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
index a0cc4cb96444..842757edb3df 100644
--- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
+++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
@@ -1798,6 +1798,15 @@ Object {
}
`;
+exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/tag-names-with-multi-dots-multi.src 1`] = `
+Object {
+ "column": 7,
+ "index": 21,
+ "lineNumber": 2,
+ "message": "'>' expected.",
+}
+`;
+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/test-content.src 1`] = `
Object {
"column": 5,
From bf13399ce05275a21d95bfea327eb9b0356c8e2c Mon Sep 17 00:00:00 2001
From: Kanitkorn Sujautra
Date: Mon, 4 Feb 2019 04:15:23 +0900
Subject: [PATCH 66/88] docs(eslint-plugin): add missing rule and remove
duplicate rule (#200)
* add missing restrict-plus-operands
* remove duplicate rule function-name
---
packages/eslint-plugin/ROADMAP.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md
index f26d0e80175c..bd0480101cf1 100644
--- a/packages/eslint-plugin/ROADMAP.md
+++ b/packages/eslint-plugin/ROADMAP.md
@@ -1,10 +1,10 @@
# Roadmap
-✅ (28) = done
+✅ (29) = done
🌟 (79) = in ESLint core
🔌 (33) = in another plugin
🌓 (16) = implementations differ or ESLint version is missing functionality
-🛑 (70) = unimplemented
+🛑 (68) = unimplemented
## TSLint rules
@@ -87,7 +87,7 @@
| [`prefer-conditional-expression`] | 🛑 | N/A |
| [`prefer-object-spread`] | 🌟 | [`prefer-object-spread`][prefer-object-spread] |
| [`radix`] | 🌟 | [`radix`][radix] |
-| [`restrict-plus-operands`] | 🛑 | N/A |
+| [`restrict-plus-operands`] | ✅ | [`@typescript-eslint/restrict-plus-operands`] |
| [`strict-boolean-expressions`] | 🛑 | N/A |
| [`strict-type-predicates`] | 🛑 | N/A |
| [`switch-default`] | 🌟 | [`default-case`][default-case] |
@@ -214,7 +214,6 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint-
| `export-name` | 🛑 | N/A ([relevant plugin][plugin:import]) |
| `function-name` | 🛑 | N/A |
| `import-name` | 🛑 | N/A ([relevant plugin][plugin:import]) |
-| `function-name` | 🛑 | N/A |
| `informative-docs` | 🛑 | N/A |
| `insecure-random` | 🔌 | [custom implementation][insecure-random] |
| `max-func-body-length` | 🌟 | [`max-statements`][max-statements] |
@@ -577,6 +576,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint-
[`@typescript-eslint/no-extraneous-class`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extraneous-class.md
[`@typescript-eslint/no-unused-vars`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
[`@typescript-eslint/no-use-before-define`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md
+[`@typescript-eslint/restrict-plus-operands`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-plus-operands.md
[`@typescript-eslint/indent`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md
[`@typescript-eslint/array-type`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
[`@typescript-eslint/class-name-casing`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/class-name-casing.md
From 773723b4e38e7b33f43fff0c9e4a109742ebb332 Mon Sep 17 00:00:00 2001
From: Armano
Date: Sun, 3 Feb 2019 21:32:51 +0100
Subject: [PATCH 67/88] refactor(ts-estree): add types to converter (#156)
---
.../typescript-estree/src/ast-converter.ts | 27 +-
.../typescript-estree/src/convert-comments.ts | 55 +-
packages/typescript-estree/src/convert.ts | 3903 ++++++++---------
.../src/estree/experimental.ts | 30 -
.../src/estree/extensions.ts | 63 -
packages/typescript-estree/src/estree/spec.ts | 985 -----
packages/typescript-estree/src/node-utils.ts | 228 +-
.../typescript-estree/src/parser-options.ts | 35 +
packages/typescript-estree/src/parser.ts | 44 +-
.../src/temp-types-based-on-js-source.ts | 106 -
.../typescript-estree/src/tsconfig-parser.ts | 25 +-
packages/typescript-estree/src/typedefs.ts | 1409 ++++++
.../typescript-estree/tests/lib/comments.ts | 2 +-
.../typescript-estree/tests/lib/javascript.ts | 2 +-
packages/typescript-estree/tests/lib/jsx.ts | 2 +-
packages/typescript-estree/tests/lib/parse.ts | 2 +-
.../tests/lib/semanticInfo.ts | 2 +-
packages/typescript-estree/tests/lib/tsx.ts | 2 +-
.../typescript-estree/tests/lib/typescript.ts | 2 +-
.../typescript-estree/tools/test-utils.ts | 2 +-
20 files changed, 3568 insertions(+), 3358 deletions(-)
delete mode 100644 packages/typescript-estree/src/estree/experimental.ts
delete mode 100644 packages/typescript-estree/src/estree/extensions.ts
delete mode 100644 packages/typescript-estree/src/estree/spec.ts
create mode 100644 packages/typescript-estree/src/parser-options.ts
delete mode 100644 packages/typescript-estree/src/temp-types-based-on-js-source.ts
create mode 100644 packages/typescript-estree/src/typedefs.ts
diff --git a/packages/typescript-estree/src/ast-converter.ts b/packages/typescript-estree/src/ast-converter.ts
index 13d2212c5c4f..131539a981b8 100644
--- a/packages/typescript-estree/src/ast-converter.ts
+++ b/packages/typescript-estree/src/ast-converter.ts
@@ -5,11 +5,11 @@
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/
-import convert, { getASTMaps, resetASTMaps, convertError } from './convert';
+import { convertError, Converter } from './convert';
import { convertComments } from './convert-comments';
import { convertTokens } from './node-utils';
import ts from 'typescript';
-import { Extra } from './temp-types-based-on-js-source';
+import { Extra } from './parser-options';
export default function astConverter(
ast: ts.SourceFile,
@@ -27,17 +27,14 @@ export default function astConverter(
/**
* Recursively convert the TypeScript AST into an ESTree-compatible AST
*/
- const estree: any = convert({
- node: ast,
- parent: null,
- ast,
- additionalOptions: {
- errorOnUnknownASTType: extra.errorOnUnknownASTType || false,
- useJSXTextNode: extra.useJSXTextNode || false,
- shouldProvideParserServices
- }
+ const instance = new Converter(ast, {
+ errorOnUnknownASTType: extra.errorOnUnknownASTType || false,
+ useJSXTextNode: extra.useJSXTextNode || false,
+ shouldProvideParserServices
});
+ const estree = instance.convertProgram();
+
/**
* Optionally convert and include all tokens in the AST
*/
@@ -52,11 +49,9 @@ export default function astConverter(
estree.comments = convertComments(ast, extra.code);
}
- let astMaps = undefined;
- if (shouldProvideParserServices) {
- astMaps = getASTMaps();
- resetASTMaps();
- }
+ const astMaps = shouldProvideParserServices
+ ? instance.getASTMaps()
+ : undefined;
return { estree, astMaps };
}
diff --git a/packages/typescript-estree/src/convert-comments.ts b/packages/typescript-estree/src/convert-comments.ts
index ac7f8504d8aa..59a2326122c8 100644
--- a/packages/typescript-estree/src/convert-comments.ts
+++ b/packages/typescript-estree/src/convert-comments.ts
@@ -7,31 +7,28 @@
import ts from 'typescript';
import { getLocFor, getNodeContainer } from './node-utils';
-import {
- ESTreeComment,
- LineAndColumnData
-} from './temp-types-based-on-js-source';
+import * as es from './typedefs';
/**
* Converts a TypeScript comment to an Esprima comment.
- * @param {boolean} block True if it's a block comment, false if not.
- * @param {string} text The text of the comment.
- * @param {number} start The index at which the comment starts.
- * @param {number} end The index at which the comment ends.
- * @param {LineAndColumnData} startLoc The location at which the comment starts.
- * @param {LineAndColumnData} endLoc The location at which the comment ends.
- * @returns {Object} The comment object.
- * @private
+ * @param block True if it's a block comment, false if not.
+ * @param text The text of the comment.
+ * @param start The index at which the comment starts.
+ * @param end The index at which the comment ends.
+ * @param startLoc The location at which the comment starts.
+ * @param endLoc The location at which the comment ends.
+ * @returns The comment object.
+ * @internal
*/
function convertTypeScriptCommentToEsprimaComment(
block: boolean,
text: string,
start: number,
end: number,
- startLoc: LineAndColumnData,
- endLoc: LineAndColumnData
-): ESTreeComment {
- const comment: ESTreeComment = {
+ startLoc: es.LineAndColumnData,
+ endLoc: es.LineAndColumnData
+): es.Comment {
+ const comment: es.OptionalRangeAndLoc = {
type: block ? 'Block' : 'Line',
value: text
};
@@ -47,22 +44,22 @@ function convertTypeScriptCommentToEsprimaComment(
};
}
- return comment;
+ return comment as es.Comment;
}
/**
* Convert comment from TypeScript Triva Scanner.
- * @param {ts.Scanner} triviaScanner TS Scanner
- * @param {ts.SourceFile} ast the AST object
- * @param {string} code TypeScript code
- * @returns {ESTreeComment} the converted ESTreeComment
+ * @param triviaScanner TS Scanner
+ * @param ast the AST object
+ * @param code TypeScript code
+ * @returns the converted Comment
* @private
*/
function getCommentFromTriviaScanner(
triviaScanner: ts.Scanner,
ast: ts.SourceFile,
code: string
-): ESTreeComment {
+): es.Comment {
const kind = triviaScanner.getToken();
const isBlock = kind === ts.SyntaxKind.MultiLineCommentTrivia;
const range = {
@@ -77,7 +74,7 @@ function getCommentFromTriviaScanner(
: comment.replace(/^\/\//, '');
const loc = getLocFor(range.pos, range.end, ast);
- const esprimaComment = convertTypeScriptCommentToEsprimaComment(
+ return convertTypeScriptCommentToEsprimaComment(
isBlock,
text,
range.pos,
@@ -85,22 +82,20 @@ function getCommentFromTriviaScanner(
loc.start,
loc.end
);
-
- return esprimaComment;
}
/**
* Convert all comments for the given AST.
- * @param {ts.SourceFile} ast the AST object
- * @param {string} code the TypeScript code
- * @returns {ESTreeComment[]} the converted ESTreeComment
+ * @param ast the AST object
+ * @param code the TypeScript code
+ * @returns the converted ESTreeComment
* @private
*/
export function convertComments(
ast: ts.SourceFile,
code: string
-): ESTreeComment[] {
- const comments: ESTreeComment[] = [];
+): es.Comment[] {
+ const comments: es.Comment[] = [];
/**
* Create a TypeScript Scanner, with skipTrivia set to false so that
diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts
index 9a7adebc8e2e..8e2d6a876a15 100644
--- a/packages/typescript-estree/src/convert.ts
+++ b/packages/typescript-estree/src/convert.ts
@@ -6,65 +6,44 @@
* MIT License
*/
import ts from 'typescript';
+import * as es from './typedefs';
import {
canContainDirective,
+ convertToken,
createError,
- getLoc,
- getLocFor,
findNextToken,
- convertToken,
- hasModifier,
fixExports,
- getTSNodeAccessibility,
+ getBinaryExpressionType,
+ getDeclarationKind,
+ getLastModifier,
+ getLineAndCharacterFor,
+ getLocFor,
+ getRange,
getTextForTokenKind,
- isJSXToken,
+ getTSNodeAccessibility,
+ hasModifier,
+ isComma,
isComputedProperty,
isESTreeClassMember,
- isComma,
- getBinaryExpressionType,
+ isJSXToken,
isOptional,
- unescapeStringLiteralText,
- getDeclarationKind,
- getLastModifier,
- getLineAndCharacterFor
+ unescapeStringLiteralText
} from './node-utils';
import { AST_NODE_TYPES } from './ast-node-types';
-import { ESTreeNode } from './temp-types-based-on-js-source';
import { TSNode } from './ts-nodes';
const SyntaxKind = ts.SyntaxKind;
-let esTreeNodeToTSNodeMap = new WeakMap();
-let tsNodeToESTreeNodeMap = new WeakMap();
-
-export function resetASTMaps() {
- esTreeNodeToTSNodeMap = new WeakMap();
- tsNodeToESTreeNodeMap = new WeakMap();
-}
-
-export function getASTMaps() {
- return { esTreeNodeToTSNodeMap, tsNodeToESTreeNodeMap };
-}
-
-interface ConvertAdditionalOptions {
+interface ConverterOptions {
errorOnUnknownASTType: boolean;
useJSXTextNode: boolean;
shouldProvideParserServices: boolean;
}
-interface ConvertConfig {
- node: ts.Node;
- parent?: ts.Node | null;
- inTypeMode?: boolean;
- allowPattern?: boolean;
- ast: ts.SourceFile;
- additionalOptions: ConvertAdditionalOptions;
-}
-
/**
* Extends and formats a given error object
- * @param {Object} error the error object
- * @returns {Object} converted error object
+ * @param error the error object
+ * @returns converted error object
*/
export function convertError(error: any) {
return createError(
@@ -74,121 +53,171 @@ export function convertError(error: any) {
);
}
-/**
- * Converts a TypeScript node into an ESTree node
- * @param {Object} config configuration options for the conversion
- * @param {TSNode} config.node the ts.Node
- * @param {ts.Node} config.parent the parent ts.Node
- * @param {ts.SourceFile} config.ast the full TypeScript AST
- * @param {Object} config.additionalOptions additional options for the conversion
- * @returns {ESTreeNode|null} the converted ESTreeNode
- */
-export default function convert(config: ConvertConfig): ESTreeNode | null {
- const node: TSNode = config.node as TSNode;
- const parent = config.parent;
- const ast = config.ast;
- const additionalOptions = config.additionalOptions || {};
+export class Converter {
+ private readonly ast: ts.SourceFile;
+ private options: ConverterOptions;
+ private esTreeNodeToTSNodeMap = new WeakMap();
+ private tsNodeToESTreeNodeMap = new WeakMap();
+
+ private allowPattern: boolean = false;
+ private inTypeMode: boolean = false;
/**
- * Exit early for null and undefined
+ * Converts a TypeScript node into an ESTree node
+ * @param ast the full TypeScript AST
+ * @param options additional options for the conversion
+ * @returns the converted ESTreeNode
*/
- if (!node) {
- return null;
+ constructor(ast: ts.SourceFile, options: ConverterOptions) {
+ this.ast = ast;
+ this.options = options;
+ }
+
+ getASTMaps() {
+ return {
+ esTreeNodeToTSNodeMap: this.esTreeNodeToTSNodeMap,
+ tsNodeToESTreeNodeMap: this.tsNodeToESTreeNodeMap
+ };
+ }
+
+ convertProgram(): es.Program {
+ return this.converter(this.ast) as es.Program;
}
/**
- * Create a new ESTree node
+ * Converts a TypeScript node into an ESTree node.
+ * @param node the child ts.Node
+ * @param parent parentNode
+ * @param inTypeMode flag to determine if we are in typeMode
+ * @param allowPattern flag to determine if patterns are allowed
+ * @returns the converted ESTree node
*/
- let result: ESTreeNode = {
- type: '' as AST_NODE_TYPES,
- range: [node.getStart(ast), node.end],
- loc: getLoc(node, ast)
- };
-
- function converter(
- child?: ts.Node,
+ private converter(
+ node?: ts.Node,
+ parent?: ts.Node,
inTypeMode?: boolean,
allowPattern?: boolean
- ): ESTreeNode | null {
- if (!child) {
+ ): any {
+ /**
+ * Exit early for null and undefined
+ */
+ if (!node) {
return null;
}
- return convert({
- node: child,
- parent: node,
- inTypeMode,
- allowPattern,
- ast,
- additionalOptions
- });
+
+ const typeMode = this.inTypeMode;
+ const pattern = this.allowPattern;
+ if (inTypeMode !== undefined) {
+ this.inTypeMode = inTypeMode;
+ }
+ if (allowPattern !== undefined) {
+ this.allowPattern = allowPattern;
+ }
+
+ let result: es.BaseNode | null = this.convertNode(
+ node as TSNode,
+ parent || node.parent
+ );
+
+ if (result && this.options.shouldProvideParserServices) {
+ this.tsNodeToESTreeNodeMap.set(node, result);
+ this.esTreeNodeToTSNodeMap.set(result, node);
+ }
+
+ this.inTypeMode = typeMode;
+ this.allowPattern = pattern;
+ return result;
}
/**
* Converts a TypeScript node into an ESTree node.
- * @param {ts.Node} child the child ts.Node
- * @returns {ESTreeNode|null} the converted ESTree node
+ * @param child the child ts.Node
+ * @param parent parentNode
+ * @returns the converted ESTree node
*/
- function convertPattern(child?: ts.Node): ESTreeNode | null {
- return converter(child, config.inTypeMode, true);
+ private convertPattern(child?: ts.Node, parent?: ts.Node): any | null {
+ return this.converter(child, parent, this.inTypeMode, true);
}
/**
* Converts a TypeScript node into an ESTree node.
- * @param {ts.Node} child the child ts.Node
- * @returns {ESTreeNode|null} the converted ESTree node
+ * @param child the child ts.Node
+ * @param parent parentNode
+ * @returns the converted ESTree node
*/
- function convertChild(child?: ts.Node): ESTreeNode | null {
- return converter(child, config.inTypeMode, false);
+ private convertChild(child?: ts.Node, parent?: ts.Node): any | null {
+ return this.converter(child, parent, this.inTypeMode, false);
}
/**
* Converts a TypeScript node into an ESTree node.
- * @param {ts.Node} child the child ts.Node
- * @returns {ESTreeNode|null} the converted ESTree node
+ * @param child the child ts.Node
+ * @param parent parentNode
+ * @returns the converted ESTree node
*/
- function convertChildType(child?: ts.Node): ESTreeNode | null {
- return converter(child, true, false);
+ private convertType(child?: ts.Node, parent?: ts.Node): any | null {
+ return this.converter(child, parent, true, false);
+ }
+
+ private createNode(
+ node: ts.Node,
+ data: es.OptionalRangeAndLoc
+ ): T {
+ const result = data;
+ if (!result.range) {
+ result.range = getRange(node, this.ast);
+ }
+ if (!result.loc) {
+ result.loc = getLocFor(result.range[0], result.range[1], this.ast);
+ }
+
+ return result as T;
}
/**
* Converts a child into a type annotation. This creates an intermediary
* TypeAnnotation node to match what Flow does.
- * @param {ts.TypeNode} child The TypeScript AST node to convert.
- * @returns {ESTreeNode} The type annotation node.
+ * @param child The TypeScript AST node to convert.
+ * @param parent parentNode
+ * @returns The type annotation node.
*/
- function convertTypeAnnotation(child: ts.TypeNode): ESTreeNode {
- const annotation = convertChildType(child);
+ private convertTypeAnnotation(
+ child: ts.TypeNode,
+ parent: ts.Node
+ ): es.TSTypeAnnotation {
// in FunctionType and ConstructorType typeAnnotation has 2 characters `=>` and in other places is just colon
const offset =
- node.kind === SyntaxKind.FunctionType ||
- node.kind === SyntaxKind.ConstructorType
+ parent.kind === SyntaxKind.FunctionType ||
+ parent.kind === SyntaxKind.ConstructorType
? 2
: 1;
const annotationStartCol = child.getFullStart() - offset;
- const loc = getLocFor(annotationStartCol, child.end, ast);
+ const loc = getLocFor(annotationStartCol, child.end, this.ast);
return {
type: AST_NODE_TYPES.TSTypeAnnotation,
loc,
range: [annotationStartCol, child.end],
- typeAnnotation: annotation
+ typeAnnotation: this.convertType(child)
};
}
/**
* Coverts body Nodes and add directive field to StringLiterals
- * @param {ts.NodeArray} nodes of ts.Node
- * @returns {ESTreeNode[]} Array of body statements
+ * @param nodes of ts.Node
+ * @param parent parentNode
+ * @returns Array of body statements
*/
- function convertBodyExpressions(
- nodes: ts.NodeArray
- ): ESTreeNode[] {
- let allowDirectives = canContainDirective(node);
+ private convertBodyExpressions(
+ nodes: ts.NodeArray,
+ parent: ts.Node
+ ): any[] {
+ let allowDirectives = canContainDirective(parent);
return (
nodes
.map(statement => {
- const child = convertChild(statement);
+ const child = this.convertChild(statement);
if (allowDirectives) {
if (
child &&
@@ -196,14 +225,14 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
ts.isExpressionStatement(statement) &&
ts.isStringLiteral(statement.expression)
) {
- const raw = child.expression.raw!;
+ const raw = child.expression.raw;
child.directive = raw.slice(1, -1);
- return child!; // child can be null but it's filtered below
+ return child; // child can be null but it's filtered below
} else {
allowDirectives = false;
}
}
- return child!; // child can be null but it's filtered below
+ return child; // child can be null but it's filtered below
})
// filter out unknown nodes for now
.filter(statement => statement)
@@ -212,58 +241,60 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
/**
* Converts a ts.Node's typeArguments to TSTypeParameterInstantiation node
- * @param {ts.NodeArray} typeArguments ts.Node typeArguments
- * @returns {ESTreeNode} TypeParameterInstantiation node
+ * @param typeArguments ts.Node typeArguments
+ * @returns TypeParameterInstantiation node
*/
- function convertTypeArgumentsToTypeParameters(
- typeArguments: ts.NodeArray
- ): ESTreeNode {
- const greaterThanToken = findNextToken(typeArguments, ast, ast)!;
+ private convertTypeArgumentsToTypeParameters(
+ typeArguments: ts.NodeArray
+ ): es.TSTypeParameterInstantiation {
+ const greaterThanToken = findNextToken(typeArguments, this.ast, this.ast)!;
return {
type: AST_NODE_TYPES.TSTypeParameterInstantiation,
range: [typeArguments.pos - 1, greaterThanToken.end],
- loc: getLocFor(typeArguments.pos - 1, greaterThanToken.end, ast),
- params: typeArguments.map(typeArgument => convertChildType(typeArgument))
+ loc: getLocFor(typeArguments.pos - 1, greaterThanToken.end, this.ast),
+ params: typeArguments.map(typeArgument => this.convertType(typeArgument))
};
}
/**
* Converts a ts.Node's typeParameters to TSTypeParameterDeclaration node
- * @param {ts.NodeArray} typeParameters ts.Node typeParameters
- * @returns {ESTreeNode} TypeParameterDeclaration node
+ * @param typeParameters ts.Node typeParameters
+ * @returns TypeParameterDeclaration node
*/
- function convertTSTypeParametersToTypeParametersDeclaration(
- typeParameters: ts.NodeArray
- ): ESTreeNode {
- const greaterThanToken = findNextToken(typeParameters, ast, ast)!;
+ private convertTSTypeParametersToTypeParametersDeclaration(
+ typeParameters: ts.NodeArray
+ ): es.TSTypeParameterDeclaration {
+ const greaterThanToken = findNextToken(typeParameters, this.ast, this.ast)!;
return {
type: AST_NODE_TYPES.TSTypeParameterDeclaration,
range: [typeParameters.pos - 1, greaterThanToken.end],
- loc: getLocFor(typeParameters.pos - 1, greaterThanToken.end, ast),
+ loc: getLocFor(typeParameters.pos - 1, greaterThanToken.end, this.ast),
params: typeParameters.map(typeParameter =>
- convertChildType(typeParameter)
+ this.convertType(typeParameter)
)
};
}
/**
* Converts an array of ts.Node parameters into an array of ESTreeNode params
- * @param {ts.Node[]} parameters An array of ts.Node params to be converted
- * @returns {ESTreeNode[]} an array of converted ESTreeNode params
+ * @param parameters An array of ts.Node params to be converted
+ * @returns an array of converted ESTreeNode params
*/
- function convertParameters(parameters: ts.NodeArray): ESTreeNode[] {
+ private convertParameters(
+ parameters: ts.NodeArray
+ ): (es.TSParameterProperty | es.RestElement | es.AssignmentPattern)[] {
if (!parameters || !parameters.length) {
return [];
}
return parameters.map(param => {
- const convertedParam = convertChild(param)!;
+ const convertedParam = this.convertChild(param);
if (!param.decorators || !param.decorators.length) {
return convertedParam;
}
return Object.assign(convertedParam, {
- decorators: param.decorators.map(convertChild)
+ decorators: param.decorators.map(el => this.convertChild(el))
});
});
}
@@ -272,21 +303,20 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
* For nodes that are copied directly from the TypeScript AST into
* ESTree mostly as-is. The only difference is the addition of a type
* property instead of a kind property. Recursively copies all children.
- * @returns {void}
*/
- function deeplyCopy(): void {
+ private deeplyCopy(node: ts.Node): any {
const customType = `TS${SyntaxKind[node.kind]}` as AST_NODE_TYPES;
/**
* If the "errorOnUnknownASTType" option is set to true, throw an error,
* otherwise fallback to just including the unknown type as-is.
*/
- if (
- additionalOptions.errorOnUnknownASTType &&
- !AST_NODE_TYPES[customType]
- ) {
+ if (this.options.errorOnUnknownASTType && !AST_NODE_TYPES[customType]) {
throw new Error(`Unknown AST_NODE_TYPE: "${customType}"`);
}
- result.type = customType;
+ const result = this.createNode(node, {
+ type: customType
+ });
+
Object.keys(node)
.filter(
key =>
@@ -297,83 +327,105 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
.forEach(key => {
if (key === 'type') {
result.typeAnnotation = (node as any).type
- ? convertTypeAnnotation((node as any).type)
+ ? this.convertTypeAnnotation((node as any).type, node)
: null;
} else if (key === 'typeArguments') {
result.typeParameters = (node as any).typeArguments
- ? convertTypeArgumentsToTypeParameters((node as any).typeArguments)
+ ? this.convertTypeArgumentsToTypeParameters(
+ (node as any).typeArguments
+ )
: null;
} else if (key === 'typeParameters') {
result.typeParameters = (node as any).typeParameters
- ? convertTSTypeParametersToTypeParametersDeclaration(
+ ? this.convertTSTypeParametersToTypeParametersDeclaration(
(node as any).typeParameters
)
: null;
} else if (key === 'decorators') {
if (node.decorators && node.decorators.length) {
- result.decorators = node.decorators.map(convertChild);
+ result.decorators = node.decorators.map((el: any) =>
+ this.convertChild(el)
+ );
}
} else {
if (Array.isArray((node as any)[key])) {
- (result as any)[key] = (node as any)[key].map(convertChild);
+ result[key] = (node as any)[key].map((el: any) =>
+ this.convertChild(el)
+ );
} else if (
(node as any)[key] &&
typeof (node as any)[key] === 'object' &&
(node as any)[key].kind
) {
// need to check node[key].kind to ensure we don't try to convert a symbol
- (result as any)[key] = convertChild((node as any)[key]);
+ result[key] = this.convertChild((node as any)[key]);
} else {
- (result as any)[key] = (node as any)[key];
+ result[key] = (node as any)[key];
}
}
});
+ return result;
}
/**
* Converts a TypeScript JSX node.tagName into an ESTree node.name
- * @param {ts.JsxTagNameExpression} tagName the tagName object from a JSX ts.Node
- * @returns {Object} the converted ESTree name object
+ * @param tagName the tagName object from a JSX ts.Node
+ * @param parent
+ * @returns the converted ESTree name object
*/
- function convertTypeScriptJSXTagNameToESTreeName(
- tagName: ts.JsxTagNameExpression
- ): ESTreeNode {
- const tagNameToken = convertToken(tagName, ast);
-
- if (tagNameToken.type === AST_NODE_TYPES.JSXMemberExpression) {
+ private convertTypeScriptJSXTagNameToESTreeName(
+ tagName: ts.JsxTagNameExpression,
+ parent: ts.Node
+ ): es.JSXMemberExpression | es.JSXIdentifier {
+ // TODO: remove convertToken call
+ const tagNameToken = convertToken(tagName, this.ast);
+
+ if (tagName.kind === SyntaxKind.PropertyAccessExpression) {
const isNestedMemberExpression =
- (node as any).tagName.expression.kind ===
- SyntaxKind.PropertyAccessExpression;
+ tagName.expression.kind === SyntaxKind.PropertyAccessExpression;
// Convert TSNode left and right objects into ESTreeNode object
// and property objects
- tagNameToken.object = convertChild((node as any).tagName.expression);
- tagNameToken.property = convertChild((node as any).tagName.name);
+ const object = this.convertChild(tagName.expression, parent);
+ const property = this.convertChild(tagName.name, parent);
// Assign the appropriate types
- tagNameToken.object.type = isNestedMemberExpression
+ object.type = isNestedMemberExpression
? AST_NODE_TYPES.JSXMemberExpression
: AST_NODE_TYPES.JSXIdentifier;
- tagNameToken.property.type = AST_NODE_TYPES.JSXIdentifier;
+ property.type = AST_NODE_TYPES.JSXIdentifier;
if ((tagName as any).expression.kind === SyntaxKind.ThisKeyword) {
- tagNameToken.object.name = 'this';
+ object.name = 'this';
}
+
+ return this.createNode(tagName, {
+ type: AST_NODE_TYPES.JSXMemberExpression,
+ range: tagNameToken.range,
+ loc: tagNameToken.loc,
+ object: object,
+ property: property
+ });
} else {
- tagNameToken.type = AST_NODE_TYPES.JSXIdentifier;
- tagNameToken.name = tagNameToken.value;
+ return this.createNode(tagName, {
+ type: AST_NODE_TYPES.JSXIdentifier,
+ range: tagNameToken.range,
+ loc: tagNameToken.loc,
+ name: tagNameToken.value
+ });
}
-
- delete tagNameToken.value;
-
- return tagNameToken;
}
/**
* Applies the given TS modifiers to the given result object.
- * @param {ts.ModifiersArray} modifiers original ts.Nodes from the node.modifiers array
- * @returns {void} (the current result object will be mutated)
+ * @param result
+ * @param modifiers original ts.Nodes from the node.modifiers array
+ * @returns the current result object will be mutated
+ * @deprecated This method adds not standardized `modifiers` property in nodes
*/
- function applyModifiersToResult(modifiers?: ts.ModifiersArray): void {
+ private applyModifiersToResult(
+ result: es.TSEnumDeclaration | es.TSModuleDeclaration,
+ modifiers?: ts.ModifiersArray
+ ): void {
if (!modifiers || !modifiers.length) {
return;
}
@@ -396,7 +448,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
handledModifierIndices[i] = true;
break;
case SyntaxKind.ConstKeyword:
- result.const = true;
+ (result as any).const = true;
handledModifierIndices[i] = true;
break;
case SyntaxKind.DeclareKeyword:
@@ -417,2091 +469,2022 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
if (!remainingModifiers || !remainingModifiers.length) {
return;
}
- result.modifiers = remainingModifiers.map(convertChild);
+ result.modifiers = remainingModifiers.map(el => this.convertChild(el));
}
/**
* Uses the current TSNode's end location for its `type` to adjust the location data of the given
* ESTreeNode, which should be the parent of the final typeAnnotation node
- * @param {ESTreeNode} typeAnnotationParent The node that will have its location data mutated
- * @returns {void}
+ * @param typeAnnotationParent The node that will have its location data mutated
+ * @param node
*/
- function fixTypeAnnotationParentLocation(
- typeAnnotationParent: ESTreeNode
+ private fixTypeAnnotationParentLocation(
+ typeAnnotationParent: es.BaseNode,
+ node: ts.TypeNode
): void {
- typeAnnotationParent.range[1] = (node as any).type.getEnd();
- typeAnnotationParent.loc = getLocFor(
- typeAnnotationParent.range[0],
+ typeAnnotationParent.range[1] = node.getEnd();
+ typeAnnotationParent.loc.end = getLineAndCharacterFor(
typeAnnotationParent.range[1],
- ast
+ this.ast
);
}
/**
+ * Converts a TypeScript node into an ESTree node.
* The core of the conversion logic:
* Identify and convert each relevant TypeScript SyntaxKind
+ * @param node the child ts.Node
+ * @param parent parentNode
+ * @returns the converted ESTree node
*/
- switch (node.kind) {
- case SyntaxKind.SourceFile:
- Object.assign(result, {
- type: AST_NODE_TYPES.Program,
- body: convertBodyExpressions(node.statements),
- // externalModuleIndicator is internal field in TSC
- sourceType: (node as any).externalModuleIndicator ? 'module' : 'script'
- });
+ private convertNode(node: TSNode, parent: ts.Node): es.Node | null {
+ switch (node.kind) {
+ case SyntaxKind.SourceFile: {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.Program,
+ body: this.convertBodyExpressions(node.statements, node),
+ // externalModuleIndicator is internal field in TSC
+ sourceType: (node as any).externalModuleIndicator
+ ? 'module'
+ : 'script',
+ range: [node.getStart(this.ast), node.endOfFileToken.end]
+ });
+ }
- result.range[1] = node.endOfFileToken.end;
- result.loc = getLocFor(node.getStart(ast), result.range[1], ast);
- break;
+ case SyntaxKind.Block: {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.BlockStatement,
+ body: this.convertBodyExpressions(node.statements, node)
+ });
+ }
- case SyntaxKind.Block:
- Object.assign(result, {
- type: AST_NODE_TYPES.BlockStatement,
- body: convertBodyExpressions(node.statements)
- });
- break;
+ case SyntaxKind.Identifier: {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.Identifier,
+ name: node.text
+ });
+ }
- case SyntaxKind.Identifier:
- Object.assign(result, {
- type: AST_NODE_TYPES.Identifier,
- name: node.text
- });
- break;
+ case SyntaxKind.WithStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.WithStatement,
+ object: this.convertChild(node.expression),
+ body: this.convertChild(node.statement)
+ });
- case SyntaxKind.WithStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.WithStatement,
- object: convertChild(node.expression),
- body: convertChild(node.statement)
- });
- break;
+ // Control Flow
- // Control Flow
+ case SyntaxKind.ReturnStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ReturnStatement,
+ argument: this.convertChild(node.expression)
+ });
- case SyntaxKind.ReturnStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.ReturnStatement,
- argument: convertChild(node.expression)
- });
- break;
+ case SyntaxKind.LabeledStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.LabeledStatement,
+ label: this.convertChild(node.label),
+ body: this.convertChild(node.statement)
+ });
- case SyntaxKind.LabeledStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.LabeledStatement,
- label: convertChild(node.label),
- body: convertChild(node.statement)
- });
- break;
+ case SyntaxKind.ContinueStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ContinueStatement,
+ label: this.convertChild(node.label)
+ });
- case SyntaxKind.BreakStatement:
- case SyntaxKind.ContinueStatement:
- Object.assign(result, {
- type: SyntaxKind[node.kind],
- label: convertChild(node.label)
- });
- break;
+ case SyntaxKind.BreakStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.BreakStatement,
+ label: this.convertChild(node.label)
+ });
- // Choice
+ // Choice
- case SyntaxKind.IfStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.IfStatement,
- test: convertChild(node.expression),
- consequent: convertChild(node.thenStatement),
- alternate: convertChild(node.elseStatement)
- });
- break;
+ case SyntaxKind.IfStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.IfStatement,
+ test: this.convertChild(node.expression),
+ consequent: this.convertChild(node.thenStatement),
+ alternate: this.convertChild(node.elseStatement)
+ });
- case SyntaxKind.SwitchStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.SwitchStatement,
- discriminant: convertChild(node.expression),
- cases: node.caseBlock.clauses.map(convertChild)
- });
- break;
-
- case SyntaxKind.CaseClause:
- case SyntaxKind.DefaultClause:
- Object.assign(result, {
- type: AST_NODE_TYPES.SwitchCase,
- // expression is present in case only
- test:
- node.kind === SyntaxKind.CaseClause
- ? convertChild(node.expression)
- : null,
- consequent: node.statements.map(convertChild)
- });
- break;
+ case SyntaxKind.SwitchStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.SwitchStatement,
+ discriminant: this.convertChild(node.expression),
+ cases: node.caseBlock.clauses.map(el => this.convertChild(el))
+ });
- // Exceptions
+ case SyntaxKind.CaseClause:
+ case SyntaxKind.DefaultClause:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.SwitchCase,
+ // expression is present in case only
+ test:
+ node.kind === SyntaxKind.CaseClause
+ ? this.convertChild(node.expression)
+ : null,
+ consequent: node.statements.map(el => this.convertChild(el))
+ });
- case SyntaxKind.ThrowStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.ThrowStatement,
- argument: convertChild(node.expression)
- });
- break;
-
- case SyntaxKind.TryStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.TryStatement,
- block: convert({
- node: node.tryBlock,
- parent: null,
- ast,
- additionalOptions
- }),
- handler: convertChild(node.catchClause),
- finalizer: convertChild(node.finallyBlock)
- });
- break;
-
- case SyntaxKind.CatchClause:
- Object.assign(result, {
- type: AST_NODE_TYPES.CatchClause,
- param: node.variableDeclaration
- ? convertChild(node.variableDeclaration.name)
- : null,
- body: convertChild(node.block)
- });
- break;
+ // Exceptions
- // Loops
+ case SyntaxKind.ThrowStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ThrowStatement,
+ argument: this.convertChild(node.expression)
+ });
- case SyntaxKind.WhileStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.WhileStatement,
- test: convertChild(node.expression),
- body: convertChild(node.statement)
- });
- break;
+ case SyntaxKind.TryStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.TryStatement,
+ block: this.convertChild(node.tryBlock),
+ handler: this.convertChild(node.catchClause),
+ finalizer: this.convertChild(node.finallyBlock)
+ });
- /**
- * Unlike other parsers, TypeScript calls a "DoWhileStatement"
- * a "DoStatement"
- */
- case SyntaxKind.DoStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.DoWhileStatement,
- test: convertChild(node.expression),
- body: convertChild(node.statement)
- });
- break;
-
- case SyntaxKind.ForStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.ForStatement,
- init: convertChild(node.initializer),
- test: convertChild(node.condition),
- update: convertChild(node.incrementor),
- body: convertChild(node.statement)
- });
- break;
-
- case SyntaxKind.ForInStatement:
- case SyntaxKind.ForOfStatement: {
- Object.assign(result, {
- type: SyntaxKind[node.kind],
- left: convertPattern(node.initializer),
- right: convertChild(node.expression),
- body: convertChild(node.statement)
- });
+ case SyntaxKind.CatchClause:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.CatchClause,
+ param: node.variableDeclaration
+ ? this.convertChild(node.variableDeclaration.name)
+ : null,
+ body: this.convertChild(node.block)
+ });
- // await is only available in for of statement
- if (node.kind === SyntaxKind.ForOfStatement) {
- (result as any).await = Boolean(
- node.awaitModifier &&
- node.awaitModifier.kind === SyntaxKind.AwaitKeyword
- );
- }
- break;
- }
+ // Loops
- // Declarations
+ case SyntaxKind.WhileStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.WhileStatement,
+ test: this.convertChild(node.expression),
+ body: this.convertChild(node.statement)
+ });
- case SyntaxKind.FunctionDeclaration: {
- const isDeclare = hasModifier(SyntaxKind.DeclareKeyword, node);
- let functionDeclarationType = AST_NODE_TYPES.FunctionDeclaration;
- if (isDeclare || !node.body) {
- functionDeclarationType = AST_NODE_TYPES.TSDeclareFunction;
- }
+ /**
+ * Unlike other parsers, TypeScript calls a "DoWhileStatement"
+ * a "DoStatement"
+ */
+ case SyntaxKind.DoStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.DoWhileStatement,
+ test: this.convertChild(node.expression),
+ body: this.convertChild(node.statement)
+ });
- Object.assign(result, {
- type: functionDeclarationType,
- id: convertChild(node.name),
- generator: !!node.asteriskToken,
- expression: false,
- async: hasModifier(SyntaxKind.AsyncKeyword, node),
- params: convertParameters(node.parameters),
- body: convertChild(node.body) || undefined
- });
+ case SyntaxKind.ForStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ForStatement,
+ init: this.convertChild(node.initializer),
+ test: this.convertChild(node.condition),
+ update: this.convertChild(node.incrementor),
+ body: this.convertChild(node.statement)
+ });
- // Process returnType
- if (node.type) {
- result.returnType = convertTypeAnnotation(node.type);
- }
+ case SyntaxKind.ForInStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ForInStatement,
+ left: this.convertPattern(node.initializer),
+ right: this.convertChild(node.expression),
+ body: this.convertChild(node.statement)
+ });
- if (isDeclare) {
- result.declare = true;
- }
+ case SyntaxKind.ForOfStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ForOfStatement,
+ left: this.convertPattern(node.initializer),
+ right: this.convertChild(node.expression),
+ body: this.convertChild(node.statement),
+ await: Boolean(
+ node.awaitModifier &&
+ node.awaitModifier.kind === SyntaxKind.AwaitKeyword
+ )
+ });
- // Process typeParameters
- if (node.typeParameters && node.typeParameters.length) {
- result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
- node.typeParameters
- );
- }
+ // Declarations
+
+ case SyntaxKind.FunctionDeclaration: {
+ const isDeclare = hasModifier(SyntaxKind.DeclareKeyword, node);
+
+ const result = this.createNode<
+ es.TSDeclareFunction | es.FunctionDeclaration
+ >(node, {
+ type:
+ isDeclare || !node.body
+ ? AST_NODE_TYPES.TSDeclareFunction
+ : AST_NODE_TYPES.FunctionDeclaration,
+ id: this.convertChild(node.name),
+ generator: !!node.asteriskToken,
+ expression: false,
+ async: hasModifier(SyntaxKind.AsyncKeyword, node),
+ params: this.convertParameters(node.parameters),
+ body: this.convertChild(node.body) || undefined
+ });
- // check for exports
- result = fixExports(node, result, ast);
+ // Process returnType
+ if (node.type) {
+ result.returnType = this.convertTypeAnnotation(node.type, node);
+ }
- break;
- }
+ if (isDeclare) {
+ result.declare = true;
+ }
- case SyntaxKind.VariableDeclaration: {
- Object.assign(result, {
- type: AST_NODE_TYPES.VariableDeclarator,
- id: convertPattern(node.name),
- init: convertChild(node.initializer)
- });
+ // Process typeParameters
+ if (node.typeParameters && node.typeParameters.length) {
+ result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
+ node.typeParameters
+ );
+ }
- if (node.exclamationToken) {
- (result as any).definite = true;
+ // check for exports
+ return fixExports(node, result, this.ast);
}
- if (node.type) {
- result.id!.typeAnnotation = convertTypeAnnotation(node.type);
- fixTypeAnnotationParentLocation(result.id!);
- }
- break;
- }
+ case SyntaxKind.VariableDeclaration: {
+ const result = this.createNode(node, {
+ type: AST_NODE_TYPES.VariableDeclarator,
+ id: this.convertPattern(node.name),
+ init: this.convertChild(node.initializer)
+ });
- case SyntaxKind.VariableStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.VariableDeclaration,
- declarations: node.declarationList.declarations.map(convertChild),
- kind: getDeclarationKind(node.declarationList)
- });
+ if (node.exclamationToken) {
+ result.definite = true;
+ }
- if (hasModifier(SyntaxKind.DeclareKeyword, node)) {
- result.declare = true;
+ if (node.type) {
+ result.id.typeAnnotation = this.convertTypeAnnotation(
+ node.type,
+ node
+ );
+ this.fixTypeAnnotationParentLocation(result.id, node.type);
+ }
+ return result;
}
- // check for exports
- result = fixExports(node, result, ast);
- break;
-
- // mostly for for-of, for-in
- case SyntaxKind.VariableDeclarationList:
- Object.assign(result, {
- type: AST_NODE_TYPES.VariableDeclaration,
- declarations: node.declarations.map(convertChild),
- kind: getDeclarationKind(node)
- });
- break;
-
- // Expressions
-
- case SyntaxKind.ExpressionStatement:
- Object.assign(result, {
- type: AST_NODE_TYPES.ExpressionStatement,
- expression: convertChild(node.expression)
- });
- break;
+ case SyntaxKind.VariableStatement: {
+ const result = this.createNode(node, {
+ type: AST_NODE_TYPES.VariableDeclaration,
+ declarations: node.declarationList.declarations.map(el =>
+ this.convertChild(el)
+ ),
+ kind: getDeclarationKind(node.declarationList)
+ });
- case SyntaxKind.ThisKeyword:
- Object.assign(result, {
- type: AST_NODE_TYPES.ThisExpression
- });
- break;
+ if (hasModifier(SyntaxKind.DeclareKeyword, node)) {
+ result.declare = true;
+ }
- case SyntaxKind.ArrayLiteralExpression: {
- // TypeScript uses ArrayLiteralExpression in destructuring assignment, too
- if (config.allowPattern) {
- Object.assign(result, {
- type: AST_NODE_TYPES.ArrayPattern,
- elements: node.elements.map(convertPattern)
- });
- } else {
- Object.assign(result, {
- type: AST_NODE_TYPES.ArrayExpression,
- elements: node.elements.map(convertChild)
- });
+ // check for exports
+ return fixExports(node, result, this.ast);
}
- break;
- }
- case SyntaxKind.ObjectLiteralExpression: {
- // TypeScript uses ObjectLiteralExpression in destructuring assignment, too
- if (config.allowPattern) {
- Object.assign(result, {
- type: AST_NODE_TYPES.ObjectPattern,
- properties: node.properties.map(convertPattern)
- });
- } else {
- Object.assign(result, {
- type: AST_NODE_TYPES.ObjectExpression,
- properties: node.properties.map(convertChild)
+ // mostly for for-of, for-in
+ case SyntaxKind.VariableDeclarationList:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.VariableDeclaration,
+ declarations: node.declarations.map(el => this.convertChild(el)),
+ kind: getDeclarationKind(node)
});
- }
- break;
- }
- case SyntaxKind.PropertyAssignment:
- Object.assign(result, {
- type: AST_NODE_TYPES.Property,
- key: convertChild(node.name),
- value: converter(
- node.initializer,
- config.inTypeMode,
- config.allowPattern
- ),
- computed: isComputedProperty(node.name),
- method: false,
- shorthand: false,
- kind: 'init'
- });
- break;
+ // Expressions
- case SyntaxKind.ShorthandPropertyAssignment: {
- if (node.objectAssignmentInitializer) {
- Object.assign(result, {
- type: AST_NODE_TYPES.Property,
- key: convertChild(node.name),
- value: {
- type: AST_NODE_TYPES.AssignmentPattern,
- left: convertPattern(node.name),
- right: convertChild(node.objectAssignmentInitializer),
- loc: result.loc,
- range: result.range
- },
- computed: false,
- method: false,
- shorthand: true,
- kind: 'init'
+ case SyntaxKind.ExpressionStatement:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ExpressionStatement,
+ expression: this.convertChild(node.expression)
});
- } else {
- // TODO: this node has no initializer field
- Object.assign(result, {
- type: AST_NODE_TYPES.Property,
- key: convertChild(node.name),
- value: convertChild((node as any).initializer || node.name),
- computed: false,
- method: false,
- shorthand: true,
- kind: 'init'
- });
- }
- break;
- }
-
- case SyntaxKind.ComputedPropertyName:
- return convertChild(node.expression);
-
- case SyntaxKind.PropertyDeclaration: {
- const isAbstract = hasModifier(SyntaxKind.AbstractKeyword, node);
- Object.assign(result, {
- type: isAbstract
- ? AST_NODE_TYPES.TSAbstractClassProperty
- : AST_NODE_TYPES.ClassProperty,
- key: convertChild(node.name),
- value: convertChild(node.initializer),
- computed: isComputedProperty(node.name),
- static: hasModifier(SyntaxKind.StaticKeyword, node),
- readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined
- });
-
- if (node.type) {
- result.typeAnnotation = convertTypeAnnotation(node.type);
- }
-
- if (node.decorators) {
- result.decorators = node.decorators.map(convertChild);
- }
-
- const accessibility = getTSNodeAccessibility(node);
- if (accessibility) {
- result.accessibility = accessibility;
- }
-
- if (node.name.kind === SyntaxKind.Identifier && node.questionToken) {
- result.optional = true;
- }
- if (node.exclamationToken) {
- (result as any).definite = true;
- }
+ case SyntaxKind.ThisKeyword:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ThisExpression
+ });
- if (
- (result as any).key.type === AST_NODE_TYPES.Literal &&
- node.questionToken
- ) {
- result.optional = true;
+ case SyntaxKind.ArrayLiteralExpression: {
+ // TypeScript uses ArrayLiteralExpression in destructuring assignment, too
+ if (this.allowPattern) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ArrayPattern,
+ elements: node.elements.map(el => this.convertPattern(el))
+ });
+ } else {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ArrayExpression,
+ elements: node.elements.map(el => this.convertChild(el))
+ });
+ }
}
- break;
- }
- case SyntaxKind.GetAccessor:
- case SyntaxKind.SetAccessor:
- case SyntaxKind.MethodDeclaration: {
- const method: ESTreeNode = {
- type: AST_NODE_TYPES.FunctionExpression,
- id: null,
- generator: !!node.asteriskToken,
- expression: false, // ESTreeNode as ESTreeNode here
- async: hasModifier(SyntaxKind.AsyncKeyword, node),
- body: convertChild(node.body),
- range: [node.parameters.pos - 1, result.range[1]],
- loc: {
- start: getLineAndCharacterFor(node.parameters.pos - 1, ast),
- end: result.loc.end
+ case SyntaxKind.ObjectLiteralExpression: {
+ // TypeScript uses ObjectLiteralExpression in destructuring assignment, too
+ if (this.allowPattern) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ObjectPattern,
+ properties: node.properties.map(el => this.convertPattern(el))
+ });
+ } else {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ObjectExpression,
+ properties: node.properties.map(el => this.convertChild(el))
+ });
}
- } as any;
-
- if (node.type) {
- (method as any).returnType = convertTypeAnnotation(node.type);
}
- if (parent!.kind === SyntaxKind.ObjectLiteralExpression) {
- (method as any).params = node.parameters.map(convertChild);
-
- Object.assign(result, {
+ case SyntaxKind.PropertyAssignment:
+ return this.createNode(node, {
type: AST_NODE_TYPES.Property,
- key: convertChild(node.name),
- value: method,
+ key: this.convertChild(node.name),
+ value: this.converter(
+ node.initializer,
+ node,
+ this.inTypeMode,
+ this.allowPattern
+ ),
computed: isComputedProperty(node.name),
- method: node.kind === SyntaxKind.MethodDeclaration,
+ method: false,
shorthand: false,
kind: 'init'
});
- } else {
- // class
- /**
- * Unlike in object literal methods, class method params can have decorators
- */
- (method as any).params = convertParameters(node.parameters);
+ case SyntaxKind.ShorthandPropertyAssignment: {
+ if (node.objectAssignmentInitializer) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.Property,
+ key: this.convertChild(node.name),
+ value: this.createNode(node, {
+ type: AST_NODE_TYPES.AssignmentPattern,
+ left: this.convertPattern(node.name),
+ right: this.convertChild(node.objectAssignmentInitializer)
+ }),
+ computed: false,
+ method: false,
+ shorthand: true,
+ kind: 'init'
+ });
+ } else {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.Property,
+ key: this.convertChild(node.name),
+ value: this.convertChild(node.name),
+ computed: false,
+ method: false,
+ shorthand: true,
+ kind: 'init'
+ });
+ }
+ }
- /**
- * TypeScript class methods can be defined as "abstract"
- */
- const methodDefinitionType = hasModifier(
- SyntaxKind.AbstractKeyword,
- node
- )
- ? AST_NODE_TYPES.TSAbstractMethodDefinition
- : AST_NODE_TYPES.MethodDefinition;
-
- Object.assign(result, {
- type: methodDefinitionType,
- key: convertChild(node.name),
- value: method,
+ case SyntaxKind.ComputedPropertyName:
+ return this.convertChild(node.expression);
+
+ case SyntaxKind.PropertyDeclaration: {
+ const isAbstract = hasModifier(SyntaxKind.AbstractKeyword, node);
+ const result = this.createNode<
+ es.TSAbstractClassProperty | es.ClassProperty
+ >(node, {
+ type: isAbstract
+ ? AST_NODE_TYPES.TSAbstractClassProperty
+ : AST_NODE_TYPES.ClassProperty,
+ key: this.convertChild(node.name),
+ value: this.convertChild(node.initializer),
computed: isComputedProperty(node.name),
static: hasModifier(SyntaxKind.StaticKeyword, node),
- kind: 'method'
+ readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined
});
+ if (node.type) {
+ result.typeAnnotation = this.convertTypeAnnotation(node.type, node);
+ }
+
if (node.decorators) {
- result.decorators = node.decorators.map(convertChild);
+ result.decorators = node.decorators.map(el => this.convertChild(el));
}
const accessibility = getTSNodeAccessibility(node);
if (accessibility) {
result.accessibility = accessibility;
}
- }
-
- if (
- (result as any).key.type === AST_NODE_TYPES.Identifier &&
- node.questionToken
- ) {
- (result as any).key.optional = true;
- }
- if (node.kind === SyntaxKind.GetAccessor) {
- (result as any).kind = 'get';
- } else if (node.kind === SyntaxKind.SetAccessor) {
- (result as any).kind = 'set';
- } else if (
- !(result as any).static &&
- node.name.kind === SyntaxKind.StringLiteral &&
- node.name.text === 'constructor' &&
- result.type !== AST_NODE_TYPES.Property
- ) {
- (result as any).kind = 'constructor';
- }
+ if (node.name.kind === SyntaxKind.Identifier && node.questionToken) {
+ result.optional = true;
+ }
- // Process typeParameters
- if (node.typeParameters && node.typeParameters.length) {
- if (result.type !== AST_NODE_TYPES.Property) {
- method.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
- node.typeParameters
- );
- } else {
- result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
- node.typeParameters
- );
+ if (node.exclamationToken) {
+ result.definite = true;
}
- }
- break;
- }
+ if (result.key.type === AST_NODE_TYPES.Literal && node.questionToken) {
+ result.optional = true;
+ }
+ return result;
+ }
+
+ case SyntaxKind.GetAccessor:
+ case SyntaxKind.SetAccessor:
+ case SyntaxKind.MethodDeclaration: {
+ const method = this.createNode(node, {
+ type: AST_NODE_TYPES.FunctionExpression,
+ id: null,
+ generator: !!node.asteriskToken,
+ expression: false, // ESTreeNode as ESTreeNode here
+ async: hasModifier(SyntaxKind.AsyncKeyword, node),
+ body: this.convertChild(node.body),
+ range: [node.parameters.pos - 1, node.end],
+ params: []
+ });
- // TypeScript uses this even for static methods named "constructor"
- case SyntaxKind.Constructor: {
- const lastModifier = getLastModifier(node);
- const constructorToken =
- (lastModifier && findNextToken(lastModifier, node, ast)) ||
- node.getFirstToken()!;
-
- const constructorTokenRange = [
- constructorToken.getStart(ast),
- constructorToken.end
- ];
-
- const constructor: ESTreeNode = {
- type: AST_NODE_TYPES.FunctionExpression,
- id: null,
- params: convertParameters(node.parameters),
- generator: false,
- expression: false, // is not present in ESTreeNode
- async: false,
- body: convertChild(node.body),
- range: [node.parameters.pos - 1, result.range[1]],
- loc: {
- start: getLineAndCharacterFor(node.parameters.pos - 1, ast),
- end: result.loc.end
- }
- } as any;
-
- // Process typeParameters
- if (node.typeParameters && node.typeParameters.length) {
- constructor.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
- node.typeParameters
- );
- }
+ if (node.type) {
+ method.returnType = this.convertTypeAnnotation(node.type, node);
+ }
- // Process returnType
- if (node.type) {
- constructor.returnType = convertTypeAnnotation(node.type);
- }
+ let result:
+ | es.Property
+ | es.TSAbstractMethodDefinition
+ | es.MethodDefinition;
- const constructorKey = {
- type: AST_NODE_TYPES.Identifier,
- name: 'constructor',
- range: constructorTokenRange,
- loc: getLocFor(constructorTokenRange[0], constructorTokenRange[1], ast)
- };
+ if (parent.kind === SyntaxKind.ObjectLiteralExpression) {
+ method.params = node.parameters.map(el => this.convertChild(el));
- const isStatic = hasModifier(SyntaxKind.StaticKeyword, node);
+ result = this.createNode(node, {
+ type: AST_NODE_TYPES.Property,
+ key: this.convertChild(node.name),
+ value: method,
+ computed: isComputedProperty(node.name),
+ method: node.kind === SyntaxKind.MethodDeclaration,
+ shorthand: false,
+ kind: 'init'
+ });
+ } else {
+ // class
+
+ /**
+ * Unlike in object literal methods, class method params can have decorators
+ */
+ method.params = this.convertParameters(node.parameters);
+
+ /**
+ * TypeScript class methods can be defined as "abstract"
+ */
+ const methodDefinitionType = hasModifier(
+ SyntaxKind.AbstractKeyword,
+ node
+ )
+ ? AST_NODE_TYPES.TSAbstractMethodDefinition
+ : AST_NODE_TYPES.MethodDefinition;
+
+ result = this.createNode<
+ es.TSAbstractMethodDefinition | es.MethodDefinition
+ >(node, {
+ type: methodDefinitionType,
+ key: this.convertChild(node.name),
+ value: method,
+ computed: isComputedProperty(node.name),
+ static: hasModifier(SyntaxKind.StaticKeyword, node),
+ kind: 'method'
+ });
- Object.assign(result, {
- type: hasModifier(SyntaxKind.AbstractKeyword, node)
- ? AST_NODE_TYPES.TSAbstractMethodDefinition
- : AST_NODE_TYPES.MethodDefinition,
- key: constructorKey,
- value: constructor,
- computed: false,
- static: isStatic,
- kind: isStatic ? 'method' : 'constructor'
- });
+ if (node.decorators) {
+ result.decorators = node.decorators.map(el =>
+ this.convertChild(el)
+ );
+ }
- const accessibility = getTSNodeAccessibility(node);
- if (accessibility) {
- result.accessibility = accessibility;
- }
+ const accessibility = getTSNodeAccessibility(node);
+ if (accessibility) {
+ result.accessibility = accessibility;
+ }
+ }
- break;
- }
+ if (
+ result.key.type === AST_NODE_TYPES.Identifier &&
+ node.questionToken
+ ) {
+ result.key.optional = true;
+ }
- case SyntaxKind.FunctionExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.FunctionExpression,
- id: convertChild(node.name),
- generator: !!node.asteriskToken,
- params: convertParameters(node.parameters),
- body: convertChild(node.body),
- async: hasModifier(SyntaxKind.AsyncKeyword, node),
- expression: false
- });
+ if (node.kind === SyntaxKind.GetAccessor) {
+ result.kind = 'get';
+ } else if (node.kind === SyntaxKind.SetAccessor) {
+ result.kind = 'set';
+ } else if (
+ !(result as es.MethodDefinition).static &&
+ node.name.kind === SyntaxKind.StringLiteral &&
+ node.name.text === 'constructor' &&
+ result.type !== AST_NODE_TYPES.Property
+ ) {
+ result.kind = 'constructor';
+ }
- // Process returnType
- if (node.type) {
- result.returnType = convertTypeAnnotation(node.type);
- }
+ // Process typeParameters
+ if (node.typeParameters && node.typeParameters.length) {
+ if (result.type !== AST_NODE_TYPES.Property) {
+ method.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
+ node.typeParameters
+ );
+ } else {
+ result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
+ node.typeParameters
+ );
+ }
+ }
+ return result;
+ }
+
+ // TypeScript uses this even for static methods named "constructor"
+ case SyntaxKind.Constructor: {
+ const lastModifier = getLastModifier(node);
+ const constructorToken =
+ (lastModifier && findNextToken(lastModifier, node, this.ast)) ||
+ node.getFirstToken()!;
+
+ const constructor = this.createNode(node, {
+ type: AST_NODE_TYPES.FunctionExpression,
+ id: null,
+ params: this.convertParameters(node.parameters),
+ generator: false,
+ expression: false, // is not present in ESTreeNode
+ async: false,
+ body: this.convertChild(node.body),
+ range: [node.parameters.pos - 1, node.end]
+ });
- // Process typeParameters
- if (node.typeParameters && node.typeParameters.length) {
- result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
- node.typeParameters
- );
- }
- break;
+ // Process typeParameters
+ if (node.typeParameters && node.typeParameters.length) {
+ constructor.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
+ node.typeParameters
+ );
+ }
- case SyntaxKind.SuperKeyword:
- Object.assign(result, {
- type: AST_NODE_TYPES.Super
- });
- break;
+ // Process returnType
+ if (node.type) {
+ constructor.returnType = this.convertTypeAnnotation(node.type, node);
+ }
- case SyntaxKind.ArrayBindingPattern:
- Object.assign(result, {
- type: AST_NODE_TYPES.ArrayPattern,
- elements: node.elements.map(convertPattern)
- });
- break;
+ const constructorKey = this.createNode(node, {
+ type: AST_NODE_TYPES.Identifier,
+ name: 'constructor',
+ range: [constructorToken.getStart(this.ast), constructorToken.end]
+ });
- // occurs with missing array elements like [,]
- case SyntaxKind.OmittedExpression:
- return null;
+ const isStatic = hasModifier(SyntaxKind.StaticKeyword, node);
+ const result = this.createNode<
+ es.TSAbstractMethodDefinition | es.MethodDefinition
+ >(node, {
+ type: hasModifier(SyntaxKind.AbstractKeyword, node)
+ ? AST_NODE_TYPES.TSAbstractMethodDefinition
+ : AST_NODE_TYPES.MethodDefinition,
+ key: constructorKey,
+ value: constructor,
+ computed: false,
+ static: isStatic,
+ kind: isStatic ? 'method' : 'constructor'
+ });
- case SyntaxKind.ObjectBindingPattern:
- Object.assign(result, {
- type: AST_NODE_TYPES.ObjectPattern,
- properties: node.elements.map(convertPattern)
- });
- break;
+ const accessibility = getTSNodeAccessibility(node);
+ if (accessibility) {
+ result.accessibility = accessibility;
+ }
+
+ return result;
+ }
- case SyntaxKind.BindingElement:
- if (parent!.kind === SyntaxKind.ArrayBindingPattern) {
- const arrayItem = convert({
- node: node.name,
- parent,
- ast,
- additionalOptions
+ case SyntaxKind.FunctionExpression: {
+ const result = this.createNode(node, {
+ type: AST_NODE_TYPES.FunctionExpression,
+ id: this.convertChild(node.name),
+ generator: !!node.asteriskToken,
+ params: this.convertParameters(node.parameters),
+ body: this.convertChild(node.body),
+ async: hasModifier(SyntaxKind.AsyncKeyword, node),
+ expression: false
});
- if (node.initializer) {
- Object.assign(result, {
- type: AST_NODE_TYPES.AssignmentPattern,
- left: arrayItem,
- right: convertChild(node.initializer)
- });
- } else if (node.dotDotDotToken) {
- Object.assign(result, {
- type: AST_NODE_TYPES.RestElement,
- argument: arrayItem
- });
- } else {
- return arrayItem;
+ // Process returnType
+ if (node.type) {
+ result.returnType = this.convertTypeAnnotation(node.type, node);
}
- } else if (parent!.kind === SyntaxKind.ObjectBindingPattern) {
- if (node.dotDotDotToken) {
- Object.assign(result, {
- type: AST_NODE_TYPES.RestElement,
- argument: convertChild(node.propertyName || node.name)
- });
- } else {
- Object.assign(result, {
- type: AST_NODE_TYPES.Property,
- key: convertChild(node.propertyName || node.name),
- value: convertChild(node.name),
- computed: Boolean(
- node.propertyName &&
- node.propertyName.kind === SyntaxKind.ComputedPropertyName
- ),
- method: false,
- shorthand: !node.propertyName,
- kind: 'init'
- });
+
+ // Process typeParameters
+ if (node.typeParameters && node.typeParameters.length) {
+ result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
+ node.typeParameters
+ );
}
+ return result;
+ }
- if (node.initializer) {
- (result as any).value = {
- type: AST_NODE_TYPES.AssignmentPattern,
- left: convertChild(node.name),
- right: convertChild(node.initializer),
- range: [node.name.getStart(ast), node.initializer.end],
- loc: getLocFor(node.name.getStart(ast), node.initializer.end, ast)
- };
- }
- }
- break;
-
- case SyntaxKind.ArrowFunction:
- Object.assign(result, {
- type: AST_NODE_TYPES.ArrowFunctionExpression,
- generator: false,
- id: null,
- params: convertParameters(node.parameters),
- body: convertChild(node.body),
- async: hasModifier(SyntaxKind.AsyncKeyword, node),
- expression: node.body.kind !== SyntaxKind.Block
- });
+ case SyntaxKind.SuperKeyword:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.Super
+ });
- // Process returnType
- if (node.type) {
- result.returnType = convertTypeAnnotation(node.type);
- }
+ case SyntaxKind.ArrayBindingPattern:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ArrayPattern,
+ elements: node.elements.map(el => this.convertPattern(el))
+ });
- // Process typeParameters
- if (node.typeParameters && node.typeParameters.length) {
- result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
- node.typeParameters
- );
- }
- break;
+ // occurs with missing array elements like [,]
+ case SyntaxKind.OmittedExpression:
+ return null;
- case SyntaxKind.YieldExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.YieldExpression,
- delegate: !!node.asteriskToken,
- argument: convertChild(node.expression)
- });
- break;
+ case SyntaxKind.ObjectBindingPattern:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ObjectPattern,
+ properties: node.elements.map(el => this.convertPattern(el))
+ });
- case SyntaxKind.AwaitExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.AwaitExpression,
- argument: convertChild(node.expression)
- });
- break;
-
- // Template Literals
-
- case SyntaxKind.NoSubstitutionTemplateLiteral:
- Object.assign(result, {
- type: AST_NODE_TYPES.TemplateLiteral,
- quasis: [
- {
- type: AST_NODE_TYPES.TemplateElement,
- value: {
- raw: ast.text.slice(node.getStart(ast) + 1, node.end - 1),
- cooked: node.text
- },
- tail: true,
- range: result.range,
- loc: result.loc
+ case SyntaxKind.BindingElement: {
+ if (parent.kind === SyntaxKind.ArrayBindingPattern) {
+ const arrayItem = this.convertChild(node.name, parent);
+
+ if (node.initializer) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.AssignmentPattern,
+ left: arrayItem,
+ right: this.convertChild(node.initializer)
+ });
+ } else if (node.dotDotDotToken) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.RestElement,
+ argument: arrayItem
+ });
+ } else {
+ return arrayItem;
+ }
+ } else if (parent.kind === SyntaxKind.ObjectBindingPattern) {
+ let result: es.RestElement | es.Property;
+ if (node.dotDotDotToken) {
+ result = this.createNode(node, {
+ type: AST_NODE_TYPES.RestElement,
+ argument: this.convertChild(node.propertyName || node.name)
+ });
+ } else {
+ result = this.createNode(node, {
+ type: AST_NODE_TYPES.Property,
+ key: this.convertChild(node.propertyName || node.name),
+ value: this.convertChild(node.name),
+ computed: Boolean(
+ node.propertyName &&
+ node.propertyName.kind === SyntaxKind.ComputedPropertyName
+ ),
+ method: false,
+ shorthand: !node.propertyName,
+ kind: 'init'
+ });
}
- ],
- expressions: []
- });
- break;
- case SyntaxKind.TemplateExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.TemplateLiteral,
- quasis: [convertChild(node.head)],
- expressions: []
- });
+ if (node.initializer) {
+ result.value = this.createNode(node, {
+ type: AST_NODE_TYPES.AssignmentPattern,
+ left: this.convertChild(node.name),
+ right: this.convertChild(node.initializer),
+ range: [node.name.getStart(this.ast), node.initializer.end]
+ });
+ }
+ return result;
+ }
+ return null;
+ }
+
+ case SyntaxKind.ArrowFunction: {
+ const result = this.createNode(node, {
+ type: AST_NODE_TYPES.ArrowFunctionExpression,
+ generator: false,
+ id: null,
+ params: this.convertParameters(node.parameters),
+ body: this.convertChild(node.body),
+ async: hasModifier(SyntaxKind.AsyncKeyword, node),
+ expression: node.body.kind !== SyntaxKind.Block
+ });
- node.templateSpans.forEach(templateSpan => {
- (result as any).expressions.push(convertChild(templateSpan.expression));
- (result as any).quasis.push(convertChild(templateSpan.literal));
- });
- break;
-
- case SyntaxKind.TaggedTemplateExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.TaggedTemplateExpression,
- typeParameters: node.typeArguments
- ? convertTypeArgumentsToTypeParameters(node.typeArguments)
- : undefined,
- tag: convertChild(node.tag),
- quasi: convertChild(node.template)
- });
- break;
-
- case SyntaxKind.TemplateHead:
- case SyntaxKind.TemplateMiddle:
- case SyntaxKind.TemplateTail: {
- const tail = node.kind === SyntaxKind.TemplateTail;
- Object.assign(result, {
- type: AST_NODE_TYPES.TemplateElement,
- value: {
- raw: ast.text.slice(
- node.getStart(ast) + 1,
- node.end - (tail ? 1 : 2)
- ),
- cooked: node.text
- },
- tail
- });
- break;
- }
+ // Process returnType
+ if (node.type) {
+ result.returnType = this.convertTypeAnnotation(node.type, node);
+ }
- // Patterns
+ // Process typeParameters
+ if (node.typeParameters && node.typeParameters.length) {
+ result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
+ node.typeParameters
+ );
+ }
+ return result;
+ }
- case SyntaxKind.SpreadAssignment:
- case SyntaxKind.SpreadElement: {
- if (config.allowPattern) {
- Object.assign(result, {
- type: AST_NODE_TYPES.RestElement,
- argument: convertPattern(node.expression)
- });
- } else {
- Object.assign(result, {
- type: AST_NODE_TYPES.SpreadElement,
- argument: convertChild(node.expression)
+ case SyntaxKind.YieldExpression:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.YieldExpression,
+ delegate: !!node.asteriskToken,
+ argument: this.convertChild(node.expression)
});
- }
- break;
- }
- case SyntaxKind.Parameter: {
- let parameter: ESTreeNode;
+ case SyntaxKind.AwaitExpression:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.AwaitExpression,
+ argument: this.convertChild(node.expression)
+ });
- if (node.dotDotDotToken) {
- Object.assign(result, {
- type: AST_NODE_TYPES.RestElement,
- argument: convertChild(node.name)
+ // Template Literals
+
+ case SyntaxKind.NoSubstitutionTemplateLiteral:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.TemplateLiteral,
+ quasis: [
+ this.createNode(node, {
+ type: AST_NODE_TYPES.TemplateElement,
+ value: {
+ raw: this.ast.text.slice(
+ node.getStart(this.ast) + 1,
+ node.end - 1
+ ),
+ cooked: node.text
+ },
+ tail: true
+ })
+ ],
+ expressions: []
});
- parameter = result;
- } else if (node.initializer) {
- parameter = convertChild(node.name)!;
- Object.assign(result, {
- type: AST_NODE_TYPES.AssignmentPattern,
- left: parameter,
- right: convertChild(node.initializer)
+
+ case SyntaxKind.TemplateExpression: {
+ const result = this.createNode(node, {
+ type: AST_NODE_TYPES.TemplateLiteral,
+ quasis: [this.convertChild(node.head)],
+ expressions: []
});
- if (node.modifiers) {
- // AssignmentPattern should not contain modifiers in range
- result.range[0] = parameter.range[0];
- result.loc = getLocFor(result.range[0], result.range[1], ast);
- }
- } else {
- parameter = result = convert({
- node: node.name,
- parent,
- ast,
- additionalOptions
- })!;
- }
-
- if (node.type) {
- parameter.typeAnnotation = convertTypeAnnotation(node.type);
- fixTypeAnnotationParentLocation(parameter);
- }
-
- if (node.questionToken) {
- if (node.questionToken.end > parameter.range[1]) {
- parameter.range[1] = node.questionToken.end;
- parameter.loc = getLocFor(
- parameter.range[0],
- parameter.range[1],
- ast
- );
- }
- parameter.optional = true;
+ node.templateSpans.forEach(templateSpan => {
+ result.expressions.push(this.convertChild(templateSpan.expression));
+ result.quasis.push(this.convertChild(templateSpan.literal));
+ });
+ return result;
}
- if (node.modifiers) {
- return {
- type: AST_NODE_TYPES.TSParameterProperty,
- range: [node.getStart(ast), node.end],
- loc: getLoc(node, ast),
- accessibility: getTSNodeAccessibility(node) || undefined,
- readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
- static: hasModifier(SyntaxKind.StaticKeyword, node) || undefined,
- export: hasModifier(SyntaxKind.ExportKeyword, node) || undefined,
- parameter: result
- };
+ case SyntaxKind.TaggedTemplateExpression:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.TaggedTemplateExpression,
+ typeParameters: node.typeArguments
+ ? this.convertTypeArgumentsToTypeParameters(node.typeArguments)
+ : undefined,
+ tag: this.convertChild(node.tag),
+ quasi: this.convertChild(node.template)
+ });
+
+ case SyntaxKind.TemplateHead:
+ case SyntaxKind.TemplateMiddle:
+ case SyntaxKind.TemplateTail: {
+ const tail = node.kind === SyntaxKind.TemplateTail;
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.TemplateElement,
+ value: {
+ raw: this.ast.text.slice(
+ node.getStart(this.ast) + 1,
+ node.end - (tail ? 1 : 2)
+ ),
+ cooked: node.text
+ },
+ tail
+ });
}
- break;
- }
+ // Patterns
- // Classes
+ case SyntaxKind.SpreadAssignment:
+ case SyntaxKind.SpreadElement: {
+ if (this.allowPattern) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.RestElement,
+ argument: this.convertPattern(node.expression)
+ });
+ } else {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.SpreadElement,
+ argument: this.convertChild(node.expression)
+ });
+ }
+ }
- case SyntaxKind.ClassDeclaration:
- case SyntaxKind.ClassExpression: {
- const heritageClauses = node.heritageClauses || [];
- let classNodeType = SyntaxKind[node.kind];
+ case SyntaxKind.Parameter: {
+ let parameter: any;
+ let result: es.RestElement | es.AssignmentPattern;
- if (node.typeParameters && node.typeParameters.length) {
- result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
- node.typeParameters
- );
- }
+ if (node.dotDotDotToken) {
+ parameter = result = this.createNode(node, {
+ type: AST_NODE_TYPES.RestElement,
+ argument: this.convertChild(node.name)
+ });
+ } else if (node.initializer) {
+ parameter = this.convertChild(node.name);
+ result = this.createNode(node, {
+ type: AST_NODE_TYPES.AssignmentPattern,
+ left: parameter,
+ right: this.convertChild(node.initializer)
+ });
- const superClass = heritageClauses.find(
- clause => clause.token === SyntaxKind.ExtendsKeyword
- );
+ if (node.modifiers) {
+ // AssignmentPattern should not contain modifiers in range
+ result.range[0] = parameter.range[0];
+ result.loc = getLocFor(result.range[0], result.range[1], this.ast);
+ }
+ } else {
+ parameter = result = this.convertChild(node.name, parent);
+ }
- if (superClass) {
- if (superClass.types.length > 1) {
- throw createError(
- ast,
- superClass.types[1].pos,
- 'Classes can only extend a single class.'
+ if (node.type) {
+ parameter.typeAnnotation = this.convertTypeAnnotation(
+ node.type,
+ node
);
+ this.fixTypeAnnotationParentLocation(parameter, node.type);
}
- if (superClass.types[0] && superClass.types[0].typeArguments) {
- (result as any).superTypeParameters = convertTypeArgumentsToTypeParameters(
- superClass.types[0].typeArguments
- );
+ if (node.questionToken) {
+ if (node.questionToken.end > parameter.range[1]) {
+ parameter.range[1] = node.questionToken.end;
+ parameter.loc.end = getLineAndCharacterFor(
+ parameter.range[1],
+ this.ast
+ );
+ }
+ parameter.optional = true;
+ }
+
+ if (node.modifiers) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.TSParameterProperty,
+ accessibility: getTSNodeAccessibility(node) || undefined,
+ readonly:
+ hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
+ static: hasModifier(SyntaxKind.StaticKeyword, node) || undefined,
+ export: hasModifier(SyntaxKind.ExportKeyword, node) || undefined,
+ parameter: result
+ });
}
+ return result;
}
- const implementsClause = heritageClauses.find(
- clause => clause.token === SyntaxKind.ImplementsKeyword
- );
+ // Classes
- const classBodyRange = [node.members.pos - 1, node.end];
+ case SyntaxKind.ClassDeclaration:
+ case SyntaxKind.ClassExpression: {
+ const heritageClauses = node.heritageClauses || [];
+ let classNodeType =
+ node.kind === SyntaxKind.ClassDeclaration
+ ? AST_NODE_TYPES.ClassDeclaration
+ : AST_NODE_TYPES.ClassExpression;
- Object.assign(result, {
- type: classNodeType,
- id: convertChild(node.name),
- body: {
- type: AST_NODE_TYPES.ClassBody,
- body: [],
- range: classBodyRange,
- loc: getLocFor(classBodyRange[0], classBodyRange[1], ast)
- },
- superClass:
- superClass && superClass.types[0]
- ? convertChild(superClass.types[0].expression)
- : null
- });
+ const superClass = heritageClauses.find(
+ clause => clause.token === SyntaxKind.ExtendsKeyword
+ );
- if (implementsClause) {
- result.implements = implementsClause.types.map(convertChild);
- }
+ const implementsClause = heritageClauses.find(
+ clause => clause.token === SyntaxKind.ImplementsKeyword
+ );
- /**
- * TypeScript class declarations can be defined as "abstract"
- */
- if (hasModifier(SyntaxKind.AbstractKeyword, node)) {
- result.abstract = true;
- }
+ const result = this.createNode<
+ es.ClassDeclaration | es.ClassExpression
+ >(node, {
+ type: classNodeType,
+ id: this.convertChild(node.name),
+ body: this.createNode(node, {
+ type: AST_NODE_TYPES.ClassBody,
+ body: [],
+ range: [node.members.pos - 1, node.end]
+ }),
+ superClass:
+ superClass && superClass.types[0]
+ ? this.convertChild(superClass.types[0].expression)
+ : null
+ });
- if (hasModifier(SyntaxKind.DeclareKeyword, node)) {
- result.declare = true;
- }
+ if (superClass) {
+ if (superClass.types.length > 1) {
+ throw createError(
+ this.ast,
+ superClass.types[1].pos,
+ 'Classes can only extend a single class.'
+ );
+ }
- if (node.decorators) {
- result.decorators = node.decorators.map(convertChild);
- }
+ if (superClass.types[0] && superClass.types[0].typeArguments) {
+ result.superTypeParameters = this.convertTypeArgumentsToTypeParameters(
+ superClass.types[0].typeArguments
+ );
+ }
+ }
- const filteredMembers = node.members.filter(isESTreeClassMember);
+ if (node.typeParameters && node.typeParameters.length) {
+ result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
+ node.typeParameters
+ );
+ }
- if (filteredMembers.length) {
- result.body.body = filteredMembers.map(convertChild);
- }
+ if (implementsClause) {
+ result.implements = implementsClause.types.map(el =>
+ this.convertChild(el)
+ );
+ }
- // check for exports
- result = fixExports(node, result, ast);
+ /**
+ * TypeScript class declarations can be defined as "abstract"
+ */
+ if (hasModifier(SyntaxKind.AbstractKeyword, node)) {
+ result.abstract = true;
+ }
- break;
- }
+ if (hasModifier(SyntaxKind.DeclareKeyword, node)) {
+ result.declare = true;
+ }
- // Modules
- case SyntaxKind.ModuleBlock:
- Object.assign(result, {
- type: AST_NODE_TYPES.TSModuleBlock,
- body: convertBodyExpressions(node.statements)
- });
- break;
+ if (node.decorators) {
+ result.decorators = node.decorators.map(el => this.convertChild(el));
+ }
- case SyntaxKind.ImportDeclaration:
- Object.assign(result, {
- type: AST_NODE_TYPES.ImportDeclaration,
- source: convertChild(node.moduleSpecifier),
- specifiers: []
- });
+ const filteredMembers = node.members.filter(isESTreeClassMember);
- if (node.importClause) {
- if (node.importClause.name) {
- result.specifiers!.push(convertChild(node.importClause));
- }
-
- if (node.importClause.namedBindings) {
- switch (node.importClause.namedBindings.kind) {
- case SyntaxKind.NamespaceImport:
- result.specifiers!.push(
- convertChild(node.importClause.namedBindings)
- );
- break;
- case SyntaxKind.NamedImports:
- result.specifiers = result.specifiers!.concat(
- node.importClause.namedBindings.elements.map(convertChild)
- );
- break;
- }
+ if (filteredMembers.length) {
+ result.body.body = filteredMembers.map(el => this.convertChild(el));
}
+
+ // check for exports
+ return fixExports(node, result, this.ast);
}
- break;
- case SyntaxKind.NamespaceImport:
- Object.assign(result, {
- type: AST_NODE_TYPES.ImportNamespaceSpecifier,
- local: convertChild(node.name)
- });
- break;
+ // Modules
+ case SyntaxKind.ModuleBlock:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.TSModuleBlock,
+ body: this.convertBodyExpressions(node.statements, node)
+ });
- case SyntaxKind.ImportSpecifier:
- Object.assign(result, {
- type: AST_NODE_TYPES.ImportSpecifier,
- local: convertChild(node.name),
- imported: convertChild(node.propertyName || node.name)
- });
- break;
+ case SyntaxKind.ImportDeclaration: {
+ const result = this.createNode(node, {
+ type: AST_NODE_TYPES.ImportDeclaration,
+ source: this.convertChild(node.moduleSpecifier),
+ specifiers: []
+ });
- case SyntaxKind.ImportClause:
- Object.assign(result, {
- type: AST_NODE_TYPES.ImportDefaultSpecifier,
- local: convertChild(node.name)
- });
+ if (node.importClause) {
+ if (node.importClause.name) {
+ result.specifiers.push(this.convertChild(node.importClause));
+ }
- // have to adjust location information due to tree differences
- result.range[1] = node.name!.end;
- result.loc = getLocFor(result.range[0], result.range[1], ast);
- break;
+ if (node.importClause.namedBindings) {
+ switch (node.importClause.namedBindings.kind) {
+ case SyntaxKind.NamespaceImport:
+ result.specifiers.push(
+ this.convertChild(node.importClause.namedBindings)
+ );
+ break;
+ case SyntaxKind.NamedImports:
+ result.specifiers = result.specifiers.concat(
+ node.importClause.namedBindings.elements.map(el =>
+ this.convertChild(el)
+ )
+ );
+ break;
+ }
+ }
+ }
+ return result;
+ }
- case SyntaxKind.ExportDeclaration:
- if (node.exportClause) {
- Object.assign(result, {
- type: AST_NODE_TYPES.ExportNamedDeclaration,
- source: convertChild(node.moduleSpecifier),
- specifiers: node.exportClause.elements.map(convertChild),
- declaration: null
- });
- } else {
- Object.assign(result, {
- type: AST_NODE_TYPES.ExportAllDeclaration,
- source: convertChild(node.moduleSpecifier)
+ case SyntaxKind.NamespaceImport:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ImportNamespaceSpecifier,
+ local: this.convertChild(node.name)
});
- }
- break;
- case SyntaxKind.ExportSpecifier:
- Object.assign(result, {
- type: AST_NODE_TYPES.ExportSpecifier,
- local: convertChild(node.propertyName || node.name),
- exported: convertChild(node.name)
- });
- break;
+ case SyntaxKind.ImportSpecifier:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ImportSpecifier,
+ local: this.convertChild(node.name),
+ imported: this.convertChild(node.propertyName || node.name)
+ });
- case SyntaxKind.ExportAssignment:
- if (node.isExportEquals) {
- Object.assign(result, {
- type: AST_NODE_TYPES.TSExportAssignment,
- expression: convertChild(node.expression)
+ case SyntaxKind.ImportClause:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ImportDefaultSpecifier,
+ local: this.convertChild(node.name),
+ range: [node.getStart(this.ast), node.name!.end]
});
- } else {
- Object.assign(result, {
- type: AST_NODE_TYPES.ExportDefaultDeclaration,
- declaration: convertChild(node.expression)
+
+ case SyntaxKind.ExportDeclaration:
+ if (node.exportClause) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ExportNamedDeclaration,
+ source: this.convertChild(node.moduleSpecifier),
+ specifiers: node.exportClause.elements.map(el =>
+ this.convertChild(el)
+ ),
+ declaration: null
+ });
+ } else {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ExportAllDeclaration,
+ source: this.convertChild(node.moduleSpecifier)
+ });
+ }
+
+ case SyntaxKind.ExportSpecifier:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ExportSpecifier,
+ local: this.convertChild(node.propertyName || node.name),
+ exported: this.convertChild(node.name)
});
- }
- break;
- // Unary Operations
+ case SyntaxKind.ExportAssignment:
+ if (node.isExportEquals) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.TSExportAssignment,
+ expression: this.convertChild(node.expression)
+ });
+ } else {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ExportDefaultDeclaration,
+ declaration: this.convertChild(node.expression)
+ });
+ }
+
+ // Unary Operations
- case SyntaxKind.PrefixUnaryExpression:
- case SyntaxKind.PostfixUnaryExpression: {
- const operator = getTextForTokenKind(node.operator) || '';
- Object.assign(result, {
+ case SyntaxKind.PrefixUnaryExpression:
+ case SyntaxKind.PostfixUnaryExpression: {
+ const operator = (getTextForTokenKind(node.operator) || '') as any;
/**
* ESTree uses UpdateExpression for ++/--
*/
- type: /^(?:\+\+|--)$/.test(operator)
- ? AST_NODE_TYPES.UpdateExpression
- : AST_NODE_TYPES.UnaryExpression,
- operator,
- prefix: node.kind === SyntaxKind.PrefixUnaryExpression,
- argument: convertChild(node.operand)
- });
- break;
- }
+ if (/^(?:\+\+|--)$/.test(operator)) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.UpdateExpression,
+ operator,
+ prefix: node.kind === SyntaxKind.PrefixUnaryExpression,
+ argument: this.convertChild(node.operand)
+ });
+ } else {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.UnaryExpression,
+ operator,
+ prefix: node.kind === SyntaxKind.PrefixUnaryExpression,
+ argument: this.convertChild(node.operand)
+ });
+ }
+ }
- case SyntaxKind.DeleteExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.UnaryExpression,
- operator: 'delete',
- prefix: true,
- argument: convertChild(node.expression)
- });
- break;
-
- case SyntaxKind.VoidExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.UnaryExpression,
- operator: 'void',
- prefix: true,
- argument: convertChild(node.expression)
- });
- break;
-
- case SyntaxKind.TypeOfExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.UnaryExpression,
- operator: 'typeof',
- prefix: true,
- argument: convertChild(node.expression)
- });
- break;
+ case SyntaxKind.DeleteExpression:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.UnaryExpression,
+ operator: 'delete',
+ prefix: true,
+ argument: this.convertChild(node.expression)
+ });
- case SyntaxKind.TypeOperator:
- Object.assign(result, {
- type: AST_NODE_TYPES.TSTypeOperator,
- operator: getTextForTokenKind(node.operator),
- typeAnnotation: convertChild(node.type)
- });
- break;
+ case SyntaxKind.VoidExpression:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.UnaryExpression,
+ operator: 'void',
+ prefix: true,
+ argument: this.convertChild(node.expression)
+ });
- // Binary Operations
+ case SyntaxKind.TypeOfExpression:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.UnaryExpression,
+ operator: 'typeof',
+ prefix: true,
+ argument: this.convertChild(node.expression)
+ });
- case SyntaxKind.BinaryExpression:
- // TypeScript uses BinaryExpression for sequences as well
- if (isComma(node.operatorToken)) {
- Object.assign(result, {
- type: AST_NODE_TYPES.SequenceExpression,
- expressions: []
+ case SyntaxKind.TypeOperator:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.TSTypeOperator,
+ operator: getTextForTokenKind(node.operator) as any,
+ typeAnnotation: this.convertChild(node.type)
});
- const left = convertChild(node.left)!,
- right = convertChild(node.right)!;
+ // Binary Operations
- if (left.type === AST_NODE_TYPES.SequenceExpression) {
- (result as any).expressions = (result as any).expressions.concat(
- (left as any).expressions
- );
- } else {
- (result as any).expressions.push(left);
- }
+ case SyntaxKind.BinaryExpression: {
+ // TypeScript uses BinaryExpression for sequences as well
+ if (isComma(node.operatorToken)) {
+ const result = this.createNode(node, {
+ type: AST_NODE_TYPES.SequenceExpression,
+ expressions: []
+ });
- if (right.type === AST_NODE_TYPES.SequenceExpression) {
- (result as any).expressions = (result as any).expressions.concat(
- (right as any).expressions
- );
+ const left = this.convertChild(node.left),
+ right = this.convertChild(node.right);
+
+ if (left.type === AST_NODE_TYPES.SequenceExpression) {
+ result.expressions = result.expressions.concat(left.expressions);
+ } else {
+ result.expressions.push(left);
+ }
+
+ if (right.type === AST_NODE_TYPES.SequenceExpression) {
+ result.expressions = result.expressions.concat(right.expressions);
+ } else {
+ result.expressions.push(right);
+ }
+ return result;
} else {
- (result as any).expressions.push(right);
- }
- } else {
- const type = getBinaryExpressionType(node.operatorToken);
- Object.assign(result, {
- type,
- operator: getTextForTokenKind(node.operatorToken.kind),
- left: converter(
- node.left,
- config.inTypeMode,
+ const type = getBinaryExpressionType(node.operatorToken);
+ if (
+ this.allowPattern &&
type === AST_NODE_TYPES.AssignmentExpression
- ),
- right: convertChild(node.right)
- });
-
- // if the binary expression is in a destructured array, switch it
- if (result.type === AST_NODE_TYPES.AssignmentExpression) {
- if (config.allowPattern) {
- delete (result as any).operator;
- result.type = AST_NODE_TYPES.AssignmentPattern;
+ ) {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.AssignmentPattern,
+ left: this.convertPattern(node.left, node),
+ right: this.convertChild(node.right)
+ });
}
+ return this.createNode<
+ es.AssignmentExpression | es.LogicalExpression | es.BinaryExpression
+ >(node, {
+ type: type,
+ operator: getTextForTokenKind(node.operatorToken.kind)!,
+ left: this.converter(
+ node.left,
+ node,
+ this.inTypeMode,
+ type === AST_NODE_TYPES.AssignmentExpression
+ ),
+ right: this.convertChild(node.right)
+ });
}
}
- break;
- case SyntaxKind.PropertyAccessExpression:
- if (isJSXToken(parent!)) {
- const jsxMemberExpression = {
- type: AST_NODE_TYPES.MemberExpression,
- object: convertChild(node.expression),
- property: convertChild(node.name)
- };
- const isNestedMemberExpression =
- node.expression.kind === SyntaxKind.PropertyAccessExpression;
- if (node.expression.kind === SyntaxKind.ThisKeyword) {
- (jsxMemberExpression as any).object.name = 'this';
- }
-
- (jsxMemberExpression as any).object.type = isNestedMemberExpression
- ? AST_NODE_TYPES.MemberExpression
- : AST_NODE_TYPES.JSXIdentifier;
- (jsxMemberExpression as any).property.type =
- AST_NODE_TYPES.JSXIdentifier;
- Object.assign(result, jsxMemberExpression);
- } else {
- Object.assign(result, {
+ case SyntaxKind.PropertyAccessExpression:
+ if (isJSXToken(parent)) {
+ const jsxMemberExpression = this.createNode(
+ node,
+ {
+ type: AST_NODE_TYPES.MemberExpression,
+ object: this.convertChild(node.expression),
+ property: this.convertChild(node.name)
+ }
+ );
+ // TODO: refactor this
+ const isNestedMemberExpression =
+ node.expression.kind === SyntaxKind.PropertyAccessExpression;
+ if (node.expression.kind === SyntaxKind.ThisKeyword) {
+ (jsxMemberExpression.object as any).name = 'this';
+ }
+
+ (jsxMemberExpression.object as any).type = isNestedMemberExpression
+ ? AST_NODE_TYPES.MemberExpression
+ : AST_NODE_TYPES.JSXIdentifier;
+ (jsxMemberExpression as any).property.type =
+ AST_NODE_TYPES.JSXIdentifier;
+ return jsxMemberExpression;
+ } else {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.MemberExpression,
+ object: this.convertChild(node.expression),
+ property: this.convertChild(node.name),
+ computed: false
+ });
+ }
+
+ case SyntaxKind.ElementAccessExpression:
+ return this.createNode(node, {
type: AST_NODE_TYPES.MemberExpression,
- object: convertChild(node.expression),
- property: convertChild(node.name),
- computed: false
+ object: this.convertChild(node.expression),
+ property: this.convertChild(node.argumentExpression),
+ computed: true
});
- }
- break;
- case SyntaxKind.ElementAccessExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.MemberExpression,
- object: convertChild(node.expression),
- property: convertChild(node.argumentExpression),
- computed: true
- });
- break;
-
- case SyntaxKind.ConditionalExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.ConditionalExpression,
- test: convertChild(node.condition),
- consequent: convertChild(node.whenTrue),
- alternate: convertChild(node.whenFalse)
- });
- break;
+ case SyntaxKind.ConditionalExpression:
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.ConditionalExpression,
+ test: this.convertChild(node.condition),
+ consequent: this.convertChild(node.whenTrue),
+ alternate: this.convertChild(node.whenFalse)
+ });
- case SyntaxKind.CallExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.CallExpression,
- callee: convertChild(node.expression),
- arguments: node.arguments.map(convertChild)
- });
- if (node.typeArguments && node.typeArguments.length) {
- result.typeParameters = convertTypeArgumentsToTypeParameters(
- node.typeArguments
- );
+ case SyntaxKind.CallExpression: {
+ const result = this.createNode(node, {
+ type: AST_NODE_TYPES.CallExpression,
+ callee: this.convertChild(node.expression),
+ arguments: node.arguments.map(el => this.convertChild(el))
+ });
+ if (node.typeArguments && node.typeArguments.length) {
+ result.typeParameters = this.convertTypeArgumentsToTypeParameters(
+ node.typeArguments
+ );
+ }
+ return result;
}
- break;
- case SyntaxKind.NewExpression:
- Object.assign(result, {
- type: AST_NODE_TYPES.NewExpression,
- callee: convertChild(node.expression),
- arguments: node.arguments ? node.arguments.map(convertChild) : []
- });
- if (node.typeArguments && node.typeArguments.length) {
- result.typeParameters = convertTypeArgumentsToTypeParameters(
- node.typeArguments
- );
+ case SyntaxKind.NewExpression: {
+ const result = this.createNode(node, {
+ type: AST_NODE_TYPES.NewExpression,
+ callee: this.convertChild(node.expression),
+ arguments: node.arguments
+ ? node.arguments.map(el => this.convertChild(el))
+ : []
+ });
+ if (node.typeArguments && node.typeArguments.length) {
+ result.typeParameters = this.convertTypeArgumentsToTypeParameters(
+ node.typeArguments
+ );
+ }
+ return result;
}
- break;
-
- case SyntaxKind.MetaProperty: {
- const newToken = convertToken(node.getFirstToken()!, ast);
- Object.assign(result, {
- type: AST_NODE_TYPES.MetaProperty,
- meta: {
- type: AST_NODE_TYPES.Identifier,
- range: newToken.range,
- loc: newToken.loc,
- name: getTextForTokenKind(node.keywordToken)
- },
- property: convertChild(node.name)
- });
- break;
- }
-
- case SyntaxKind.Decorator: {
- Object.assign(result, {
- type: AST_NODE_TYPES.Decorator,
- expression: convertChild(node.expression)
- });
- break;
- }
- // Literals
+ case SyntaxKind.MetaProperty: {
+ return this.createNode(node, {
+ type: AST_NODE_TYPES.MetaProperty,
+ meta: this.createNode(node.getFirstToken()!, {
+ type: AST_NODE_TYPES.Identifier,
+ name: getTextForTokenKind(node.keywordToken)!
+ }),
+ property: this.convertChild(node.name)
+ });
+ }
- case SyntaxKind.StringLiteral:
- Object.assign(result, {
- type: AST_NODE_TYPES.Literal,
- raw: ast.text.slice(result.range[0], result.range[1])
- });
- if ((parent as any).name && (parent as any).name === node) {
- (result as any).value = node.text;
- } else {
- (result as any).value = unescapeStringLiteralText(node.text);
- }
- break;
-
- case SyntaxKind.NumericLiteral: {
- Object.assign(result, {
- type: AST_NODE_TYPES.Literal,
- value: Number(node.text),
- raw: node.getText()
- });
- break;
- }
+ case SyntaxKind.Decorator: {
+ return this.createNode