Skip to content

Commit

Permalink
chore: upgrade local ts version to 4.0.0-beta (#2305)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Jul 19, 2020
1 parent 2eb3ca4 commit cbaac77
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -98,9 +98,9 @@
"ts-jest": "^25.5.1",
"ts-node": "^8.10.1",
"tslint": "^6.1.2",
"typescript": ">=3.3.1 <4.0.0"
"typescript": ">=3.3.1 <4.0.0 || 4.0.0-beta"
},
"resolutions": {
"typescript": "3.9.2"
"typescript": "4.0.0-beta"
}
}
1 change: 1 addition & 0 deletions packages/scope-manager/package.json
Expand Up @@ -31,6 +31,7 @@
"build": "tsc -b tsconfig.build.json",
"postbuild": "downlevel-dts dist _ts3.4/dist",
"clean": "tsc -b tsconfig.build.json --clean",
"postclean": "rimraf dist",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
"generate:lib": "../../node_modules/.bin/ts-node --files --transpile-only tools/generate-lib.ts",
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
Expand Down
1 change: 0 additions & 1 deletion packages/types/package.json
Expand Up @@ -33,7 +33,6 @@
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
"generate:lib": "../../node_modules/.bin/ts-node --files --transpile-only ../scope-manager/tools/generate-lib.ts",
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
"test": "jest --coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"funding": {
Expand Down
4 changes: 4 additions & 0 deletions packages/typescript-estree/src/ast-converter.ts
Expand Up @@ -40,9 +40,13 @@ export function astConverter(
simpleTraverse(estree, {
enter: node => {
if (!extra.range) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- TS 4.0 made this an error because the types aren't optional
// @ts-expect-error
delete node.range;
}
if (!extra.loc) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- TS 4.0 made this an error because the types aren't optional
// @ts-expect-error
delete node.loc;
}
},
Expand Down
47 changes: 27 additions & 20 deletions packages/typescript-estree/src/convert.ts
Expand Up @@ -1983,19 +1983,12 @@ export class Converter {
raw: 'false',
});

case SyntaxKind.NullKeyword: {
if (this.inTypeMode) {
return this.createNode<TSESTree.TSNullKeyword>(node, {
type: AST_NODE_TYPES.TSNullKeyword,
});
} else {
return this.createNode<TSESTree.Literal>(node as ts.NullLiteral, {
type: AST_NODE_TYPES.Literal,
value: null,
raw: 'null',
});
}
}
case SyntaxKind.NullKeyword:
return this.createNode<TSESTree.Literal>(node, {
type: AST_NODE_TYPES.Literal,
value: null,
raw: 'null',
});

case SyntaxKind.EmptyStatement:
return this.createNode<TSESTree.EmptyStatement>(node, {
Expand Down Expand Up @@ -2620,9 +2613,12 @@ export class Converter {
// In TS 4.0, the `elementTypes` property was changed to `elements`.
// To support both at compile time, we cast to access the newer version
// if the former does not exist.
const elementTypes = node.elementTypes
? node.elementTypes.map(el => this.convertType(el))
: (node as any).elements.map((el: ts.Node) => this.convertType(el));
const elementTypes =
'elementTypes' in node
? (node as any).elementTypes.map((el: ts.Node) =>
this.convertType(el),
)
: node.elements.map((el: ts.Node) => this.convertType(el));

return this.createNode<TSESTree.TSTupleType>(node, {
type: AST_NODE_TYPES.TSTupleType,
Expand Down Expand Up @@ -2661,10 +2657,21 @@ export class Converter {
});
}
case SyntaxKind.LiteralType: {
return this.createNode<TSESTree.TSLiteralType>(node, {
type: AST_NODE_TYPES.TSLiteralType,
literal: this.convertType(node.literal),
});
if (node.literal.kind === SyntaxKind.NullKeyword) {
// 4.0.0 started nesting null types inside a LiteralType node
// but our AST is designed around the old way of null being a keyword
return this.createNode<TSESTree.TSNullKeyword>(
node.literal as ts.NullLiteral,
{
type: AST_NODE_TYPES.TSNullKeyword,
},
);
} else {
return this.createNode<TSESTree.TSLiteralType>(node, {
type: AST_NODE_TYPES.TSLiteralType,
literal: this.convertType(node.literal),
});
}
}
case SyntaxKind.TypeAssertionExpression: {
return this.createNode<TSESTree.TSTypeAssertion>(node, {
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript-estree/src/node-utils.ts
Expand Up @@ -67,8 +67,11 @@ interface TokenToText {
[SyntaxKind.GreaterThanGreaterThanEqualsToken]: '>>=';
[SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: '>>>=';
[SyntaxKind.AmpersandEqualsToken]: '&=';
[SyntaxKind.AmpersandAmpersandEqualsToken]: '&&=';
[SyntaxKind.BarEqualsToken]: '|=';
[SyntaxKind.BarBarEqualsToken]: '||=';
[SyntaxKind.CaretEqualsToken]: '^=';
[SyntaxKind.QuestionQuestionEqualsToken]: '??=';
[SyntaxKind.AtToken]: '@';
[SyntaxKind.InKeyword]: 'in';
[SyntaxKind.UniqueKeyword]: 'unique';
Expand Down
Expand Up @@ -170,7 +170,7 @@ Object {
},
],
"text": "new foo<T>()",
"transformFlags": 0,
"transformFlags": 9,
"type": "TSSourceFile",
"typeReferenceDirectives": Array [],
}
Expand All @@ -190,6 +190,8 @@ Object {
"line": 1,
},
},
"localSymbol": undefined,
"locals": undefined,
"modifiers": undefined,
"name": Object {
"escapedText": "foo",
Expand All @@ -203,18 +205,21 @@ Object {
"line": 1,
},
},
"originalKeywordKind": undefined,
"range": Array [
5,
8,
],
"transformFlags": 0,
"type": "TSUnparsedPrologue",
},
"nextContainer": undefined,
"range": Array [
0,
35,
],
"transformFlags": 0,
"symbol": undefined,
"transformFlags": 1,
"type": "TSUnparsedPrologue",
"typeAnnotation": null,
"typeParameters": null,
Expand Down Expand Up @@ -289,6 +294,8 @@ Object {
"line": 1,
},
},
"localSymbol": undefined,
"locals": undefined,
"members": Array [],
"modifiers": undefined,
"name": Object {
Expand All @@ -309,11 +316,13 @@ Object {
],
"type": "Identifier",
},
"nextContainer": undefined,
"range": Array [
0,
18,
],
"transformFlags": 0,
"symbol": undefined,
"transformFlags": 2305,
"type": "TSClassDeclaration",
"typeParameters": null,
}
Expand Down Expand Up @@ -354,7 +363,7 @@ Object {
0,
12,
],
"transformFlags": 0,
"transformFlags": 9,
"type": "TSNewExpression",
"typeParameters": Object {
"loc": Object {
Expand Down Expand Up @@ -427,7 +436,10 @@ Object {
"line": 1,
},
},
"localSymbol": undefined,
"locals": undefined,
"members": Array [],
"modifiers": undefined,
"name": Object {
"loc": Object {
"end": Object {
Expand All @@ -446,11 +458,13 @@ Object {
],
"type": "Identifier",
},
"nextContainer": undefined,
"range": Array [
0,
15,
],
"transformFlags": 0,
"symbol": undefined,
"transformFlags": 257,
"type": "TSClassDeclaration",
"typeParameters": Object {
"loc": Object {
Expand Down
Expand Up @@ -1499,17 +1499,17 @@ Object {

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-no-common-parent.src 1`] = `
Object {
"column": 36,
"index": 36,
"column": 8,
"index": 8,
"lineNumber": 1,
"message": "JSX expressions must have one parent element.",
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-no-common-parent-with-comment.src 1`] = `
Object {
"column": 63,
"index": 63,
"column": 8,
"index": 8,
"lineNumber": 1,
"message": "JSX expressions must have one parent element.",
}
Expand Down
2 changes: 2 additions & 0 deletions packages/typescript-estree/tests/lib/convert.test.ts
Expand Up @@ -19,6 +19,8 @@ describe('convert', () => {

function fakeUnknownKind(node: ts.Node): void {
ts.forEachChild(node, fakeUnknownKind);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- intentionally writing to a readonly field
// @ts-expect-error
node.kind = ts.SyntaxKind.UnparsedPrologue;
}

Expand Down
Expand Up @@ -50,7 +50,7 @@ Object {
7,
14,
],
"transformFlags": 0,
"transformFlags": 1,
"type": "TSPrivateKeyword",
},
Object {
Expand All @@ -68,7 +68,7 @@ Object {
15,
21,
],
"transformFlags": 0,
"transformFlags": 1,
"type": "TSPublicKeyword",
},
Object {
Expand All @@ -86,7 +86,7 @@ Object {
22,
31,
],
"transformFlags": 0,
"transformFlags": 1,
"type": "TSProtectedKeyword",
},
Object {
Expand All @@ -104,7 +104,7 @@ Object {
32,
38,
],
"transformFlags": 0,
"transformFlags": 256,
"type": "TSStaticKeyword",
},
Object {
Expand All @@ -122,7 +122,7 @@ Object {
39,
47,
],
"transformFlags": 0,
"transformFlags": 1,
"type": "TSReadonlyKeyword",
},
Object {
Expand Down Expand Up @@ -157,7 +157,7 @@ Object {
57,
62,
],
"transformFlags": 0,
"transformFlags": 96,
"type": "TSAsyncKeyword",
},
],
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -8575,10 +8575,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@*, typescript@3.9.2, "typescript@>=3.3.1 <4.0.0", typescript@^3.8.0-dev.20200111:
version "3.9.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.2.tgz#64e9c8e9be6ea583c54607677dd4680a1cf35db9"
integrity sha512-q2ktq4n/uLuNNShyayit+DTobV2ApPEo/6so68JaD5ojvc/6GClBipedB9zNWYxRSAlZXAe405Rlijzl6qDiSw==
typescript@*, typescript@4.0.0-beta, "typescript@>=3.3.1 <4.0.0 || 4.0.0-beta", typescript@^3.8.0-dev.20200111:
version "4.0.0-beta"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.0-beta.tgz#a6a65e430562131de69496a3ef5484346bc0cdd2"
integrity sha512-d3s/CogGtB2uPZ2Z8ts6eoUxxyB9PH3R27/UrzvpthuOvpCg4FWWnBbBiqJ0K4eu6eTlgmLiqQkh2dquReJweA==

uc.micro@^1.0.1, uc.micro@^1.0.5:
version "1.0.6"
Expand Down

0 comments on commit cbaac77

Please sign in to comment.