fix: update typescript and typescript-estree to latest (#5728)
parent
282597c1e5
commit
ef6386015d
|
@ -65,8 +65,8 @@
|
|||
"resolve": "1.5.0",
|
||||
"semver": "5.4.1",
|
||||
"string-width": "3.0.0",
|
||||
"typescript": "3.2.1",
|
||||
"typescript-estree": "6.0.0-rc.1",
|
||||
"typescript": "3.2.2",
|
||||
"typescript-estree": "15.0.0",
|
||||
"unicode-regex": "2.0.0",
|
||||
"unified": "6.1.6",
|
||||
"vnopts": "1.0.2",
|
||||
|
|
|
@ -99,7 +99,7 @@ async function run(params) {
|
|||
await execa("rm", ["-rf", ".cache"]);
|
||||
}
|
||||
|
||||
const bundleCache = new Cache(".cache/", "v9");
|
||||
const bundleCache = new Cache(".cache/", "v10");
|
||||
await bundleCache.load();
|
||||
|
||||
console.log(chalk.inverse(" Building packages "));
|
||||
|
|
|
@ -37,7 +37,11 @@ const parsers = [
|
|||
},
|
||||
{
|
||||
input: "src/language-js/parser-typescript.js",
|
||||
target: "universal"
|
||||
target: "universal",
|
||||
replace: {
|
||||
// node v4 compatibility for typescript-estree
|
||||
"(!unique.includes(raw))": "(unique.indexOf(raw) === -1)"
|
||||
}
|
||||
},
|
||||
{
|
||||
input: "src/language-js/parser-angular.js",
|
||||
|
|
|
@ -61,11 +61,8 @@ function clean(ast, newObj, parent) {
|
|||
}
|
||||
|
||||
// (TypeScript) bypass TSParenthesizedType
|
||||
if (
|
||||
ast.type === "TSParenthesizedType" &&
|
||||
ast.typeAnnotation.type === "TSTypeAnnotation"
|
||||
) {
|
||||
return newObj.typeAnnotation.typeAnnotation;
|
||||
if (ast.type === "TSParenthesizedType") {
|
||||
return newObj.typeAnnotation;
|
||||
}
|
||||
|
||||
// We convert <div></div> to <div />
|
||||
|
|
|
@ -240,7 +240,7 @@ function needsParens(path, options) {
|
|||
}
|
||||
}
|
||||
// fallthrough
|
||||
case "TSTypeAssertionExpression":
|
||||
case "TSTypeAssertion":
|
||||
case "TSAsExpression":
|
||||
case "LogicalExpression":
|
||||
switch (parent.type) {
|
||||
|
@ -255,7 +255,7 @@ function needsParens(path, options) {
|
|||
case "ClassDeclaration":
|
||||
case "TSAbstractClassDeclaration":
|
||||
return name === "superClass" && parent.superClass === node;
|
||||
case "TSTypeAssertionExpression":
|
||||
case "TSTypeAssertion":
|
||||
case "TaggedTemplateExpression":
|
||||
case "UnaryExpression":
|
||||
case "SpreadElement":
|
||||
|
@ -274,19 +274,17 @@ function needsParens(path, options) {
|
|||
case "AssignmentExpression":
|
||||
return (
|
||||
parent.left === node &&
|
||||
(node.type === "TSTypeAssertionExpression" ||
|
||||
node.type === "TSAsExpression")
|
||||
(node.type === "TSTypeAssertion" || node.type === "TSAsExpression")
|
||||
);
|
||||
case "Decorator":
|
||||
return (
|
||||
parent.expression === node &&
|
||||
(node.type === "TSTypeAssertionExpression" ||
|
||||
node.type === "TSAsExpression")
|
||||
(node.type === "TSTypeAssertion" || node.type === "TSAsExpression")
|
||||
);
|
||||
|
||||
case "BinaryExpression":
|
||||
case "LogicalExpression": {
|
||||
if (!node.operator && node.type !== "TSTypeAssertionExpression") {
|
||||
if (!node.operator && node.type !== "TSTypeAssertion") {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -334,12 +332,11 @@ function needsParens(path, options) {
|
|||
if (
|
||||
(parent.type === "TSTypeParameter" ||
|
||||
parent.type === "TypeParameter" ||
|
||||
parent.type === "VariableDeclarator" ||
|
||||
parent.type === "TSTypeAliasDeclaration" ||
|
||||
parent.type === "TSTypeAnnotation" ||
|
||||
parent.type === "GenericTypeAnnotation" ||
|
||||
parent.type === "TSTypeReference") &&
|
||||
(node.typeAnnotation.type === "TSTypeAnnotation" &&
|
||||
grandParent.type !== "TSTypeOperator" &&
|
||||
parent.type === "TSParenthesizedType" ||
|
||||
parent.type === "TSTypeParameterInstantiation") &&
|
||||
(grandParent.type !== "TSTypeOperator" &&
|
||||
grandParent.type !== "TSOptionalType")
|
||||
) {
|
||||
return false;
|
||||
|
@ -527,7 +524,7 @@ function needsParens(path, options) {
|
|||
case "ExportDefaultDeclaration":
|
||||
case "AwaitExpression":
|
||||
case "JSXSpreadAttribute":
|
||||
case "TSTypeAssertionExpression":
|
||||
case "TSTypeAssertion":
|
||||
case "TypeCastExpression":
|
||||
case "TSAsExpression":
|
||||
case "TSNonNullExpression":
|
||||
|
@ -578,7 +575,7 @@ function needsParens(path, options) {
|
|||
case "LogicalExpression":
|
||||
case "BinaryExpression":
|
||||
case "AwaitExpression":
|
||||
case "TSTypeAssertionExpression":
|
||||
case "TSTypeAssertion":
|
||||
return true;
|
||||
|
||||
case "ConditionalExpression":
|
||||
|
@ -685,6 +682,7 @@ function isStatement(node) {
|
|||
node.type === "ThrowStatement" ||
|
||||
node.type === "TryStatement" ||
|
||||
node.type === "TSAbstractClassDeclaration" ||
|
||||
node.type === "TSDeclareFunction" ||
|
||||
node.type === "TSEnumDeclaration" ||
|
||||
node.type === "TSImportEqualsDeclaration" ||
|
||||
node.type === "TSInterfaceDeclaration" ||
|
||||
|
|
|
@ -414,9 +414,9 @@ function printTernaryOperator(path, options, print, operatorOptions) {
|
|||
}
|
||||
|
||||
function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
|
||||
if (tokenNode.type === "TSPlusToken") {
|
||||
if (tokenNode === "+") {
|
||||
return "+" + keyword;
|
||||
} else if (tokenNode.type === "TSMinusToken") {
|
||||
} else if (tokenNode === "-") {
|
||||
return "-" + keyword;
|
||||
}
|
||||
return keyword;
|
||||
|
@ -660,7 +660,7 @@ function printPathNoParens(path, options, print, args) {
|
|||
" = ",
|
||||
path.call(print, "right")
|
||||
]);
|
||||
case "TSTypeAssertionExpression": {
|
||||
case "TSTypeAssertion": {
|
||||
const shouldBreakAfterCast = !(
|
||||
n.expression.type === "ArrayExpression" ||
|
||||
n.expression.type === "ObjectExpression"
|
||||
|
@ -772,9 +772,6 @@ function printPathNoParens(path, options, print, args) {
|
|||
]);
|
||||
case "FunctionDeclaration":
|
||||
case "FunctionExpression":
|
||||
if (isNodeStartingWithDeclare(n, options)) {
|
||||
parts.push("declare ");
|
||||
}
|
||||
parts.push(printFunctionDeclaration(path, print, options));
|
||||
if (!n.body) {
|
||||
parts.push(semi);
|
||||
|
@ -947,20 +944,10 @@ function printPathNoParens(path, options, print, args) {
|
|||
return concat(parts);
|
||||
case "ImportNamespaceSpecifier":
|
||||
parts.push("* as ");
|
||||
|
||||
if (n.local) {
|
||||
parts.push(path.call(print, "local"));
|
||||
} else if (n.id) {
|
||||
parts.push(path.call(print, "id"));
|
||||
}
|
||||
|
||||
parts.push(path.call(print, "local"));
|
||||
return concat(parts);
|
||||
case "ImportDefaultSpecifier":
|
||||
if (n.local) {
|
||||
return path.call(print, "local");
|
||||
}
|
||||
|
||||
return path.call(print, "id");
|
||||
return path.call(print, "local");
|
||||
case "TSExportAssignment":
|
||||
return concat(["export = ", path.call(print, "expression"), semi]);
|
||||
case "ExportDefaultDeclaration":
|
||||
|
@ -1361,7 +1348,7 @@ function printPathNoParens(path, options, print, args) {
|
|||
if (
|
||||
(prop.node.type === "TSPropertySignature" ||
|
||||
prop.node.type === "TSMethodSignature" ||
|
||||
prop.node.type === "TSConstructSignature") &&
|
||||
prop.node.type === "TSConstructSignatureDeclaration") &&
|
||||
hasNodeIgnoreComment(prop.node)
|
||||
) {
|
||||
separatorParts.shift();
|
||||
|
@ -1706,10 +1693,33 @@ function printPathNoParens(path, options, print, args) {
|
|||
|
||||
return group(concat(parts));
|
||||
}
|
||||
case "TSTypeAliasDeclaration": {
|
||||
if (n.declare) {
|
||||
parts.push("declare ");
|
||||
}
|
||||
|
||||
const printed = printAssignmentRight(
|
||||
n.id,
|
||||
n.typeAnnotation,
|
||||
n.typeAnnotation && path.call(print, "typeAnnotation"),
|
||||
options
|
||||
);
|
||||
|
||||
parts.push(
|
||||
"type ",
|
||||
path.call(print, "id"),
|
||||
path.call(print, "typeParameters"),
|
||||
" =",
|
||||
printed,
|
||||
semi
|
||||
);
|
||||
|
||||
return group(concat(parts));
|
||||
}
|
||||
case "VariableDeclarator":
|
||||
return printAssignment(
|
||||
n.id,
|
||||
concat([path.call(print, "id"), path.call(print, "typeParameters")]),
|
||||
path.call(print, "id"),
|
||||
" =",
|
||||
n.init,
|
||||
n.init && path.call(print, "init"),
|
||||
|
@ -2594,16 +2604,15 @@ function printPathNoParens(path, options, print, args) {
|
|||
return "" + n.value;
|
||||
case "DeclareClass":
|
||||
return printFlowDeclaration(path, printClass(path, options, print));
|
||||
case "DeclareFunction":
|
||||
// For TypeScript the DeclareFunction node shares the AST
|
||||
case "TSDeclareFunction":
|
||||
// For TypeScript the TSDeclareFunction node shares the AST
|
||||
// structure with FunctionDeclaration
|
||||
if (n.params) {
|
||||
return concat([
|
||||
"declare ",
|
||||
printFunctionDeclaration(path, print, options),
|
||||
semi
|
||||
]);
|
||||
}
|
||||
return concat([
|
||||
n.declare ? "declare " : "",
|
||||
printFunctionDeclaration(path, print, options),
|
||||
semi
|
||||
]);
|
||||
case "DeclareFunction":
|
||||
return printFlowDeclaration(path, [
|
||||
"function ",
|
||||
path.call(print, "id"),
|
||||
|
@ -2826,7 +2835,6 @@ function printPathNoParens(path, options, print, args) {
|
|||
// | C
|
||||
|
||||
const parent = path.getParentNode();
|
||||
const parentParent = path.getParentNode(1);
|
||||
|
||||
// If there's a leading comment, the parent is doing the indentation
|
||||
const shouldIndent =
|
||||
|
@ -2834,11 +2842,12 @@ function printPathNoParens(path, options, print, args) {
|
|||
parent.type !== "TSTypeParameterInstantiation" &&
|
||||
parent.type !== "GenericTypeAnnotation" &&
|
||||
parent.type !== "TSTypeReference" &&
|
||||
parent.type !== "TSTypeAssertion" &&
|
||||
!(parent.type === "FunctionTypeParam" && !parent.name) &&
|
||||
parentParent.type !== "TSTypeAssertionExpression" &&
|
||||
!(
|
||||
(parent.type === "TypeAlias" ||
|
||||
parent.type === "VariableDeclarator") &&
|
||||
parent.type === "VariableDeclarator" ||
|
||||
parent.type === "TSTypeAliasDeclaration") &&
|
||||
hasLeadingOwnLineComment(options.originalText, n, options)
|
||||
);
|
||||
|
||||
|
@ -3249,10 +3258,10 @@ function printPathNoParens(path, options, print, args) {
|
|||
path.call(print, "indexType"),
|
||||
"]"
|
||||
]);
|
||||
case "TSConstructSignature":
|
||||
case "TSConstructorType":
|
||||
case "TSCallSignature": {
|
||||
if (n.type !== "TSCallSignature") {
|
||||
case "TSConstructSignatureDeclaration":
|
||||
case "TSCallSignatureDeclaration":
|
||||
case "TSConstructorType": {
|
||||
if (n.type !== "TSCallSignatureDeclaration") {
|
||||
parts.push("new ");
|
||||
}
|
||||
|
||||
|
@ -3268,9 +3277,9 @@ function printPathNoParens(path, options, print, args) {
|
|||
)
|
||||
);
|
||||
|
||||
if (n.typeAnnotation) {
|
||||
if (n.returnType) {
|
||||
const isType = n.type === "TSConstructorType";
|
||||
parts.push(isType ? " => " : ": ", path.call(print, "typeAnnotation"));
|
||||
parts.push(isType ? " => " : ": ", path.call(print, "returnType"));
|
||||
}
|
||||
return concat(parts);
|
||||
}
|
||||
|
@ -3283,19 +3292,16 @@ function printPathNoParens(path, options, print, args) {
|
|||
indent(
|
||||
concat([
|
||||
options.bracketSpacing ? line : softline,
|
||||
n.readonlyToken
|
||||
n.readonly
|
||||
? concat([
|
||||
getTypeScriptMappedTypeModifier(
|
||||
n.readonlyToken,
|
||||
"readonly"
|
||||
),
|
||||
getTypeScriptMappedTypeModifier(n.readonly, "readonly"),
|
||||
" "
|
||||
])
|
||||
: "",
|
||||
printTypeScriptModifiers(path, options, print),
|
||||
path.call(print, "typeParameter"),
|
||||
n.questionToken
|
||||
? getTypeScriptMappedTypeModifier(n.questionToken, "?")
|
||||
n.optional
|
||||
? getTypeScriptMappedTypeModifier(n.optional, "?")
|
||||
: "",
|
||||
": ",
|
||||
path.call(print, "typeAnnotation")
|
||||
|
@ -3325,12 +3331,12 @@ function printPathNoParens(path, options, print, args) {
|
|||
)
|
||||
);
|
||||
|
||||
if (n.typeAnnotation) {
|
||||
parts.push(": ", path.call(print, "typeAnnotation"));
|
||||
if (n.returnType) {
|
||||
parts.push(": ", path.call(print, "returnType"));
|
||||
}
|
||||
return group(concat(parts));
|
||||
case "TSNamespaceExportDeclaration":
|
||||
parts.push("export as namespace ", path.call(print, "name"));
|
||||
parts.push("export as namespace ", path.call(print, "id"));
|
||||
|
||||
if (options.semi) {
|
||||
parts.push(";");
|
||||
|
@ -3394,10 +3400,12 @@ function printPathNoParens(path, options, print, args) {
|
|||
}
|
||||
return concat(parts);
|
||||
case "TSImportEqualsDeclaration":
|
||||
if (n.isExport) {
|
||||
parts.push("export ");
|
||||
}
|
||||
parts.push(
|
||||
printTypeScriptModifiers(path, options, print),
|
||||
"import ",
|
||||
path.call(print, "name"),
|
||||
path.call(print, "id"),
|
||||
" = ",
|
||||
path.call(print, "moduleReference")
|
||||
);
|
||||
|
@ -3769,7 +3777,7 @@ function couldGroupArg(arg) {
|
|||
(arg.properties.length > 0 || arg.comments)) ||
|
||||
(arg.type === "ArrayExpression" &&
|
||||
(arg.elements.length > 0 || arg.comments)) ||
|
||||
arg.type === "TSTypeAssertionExpression" ||
|
||||
arg.type === "TSTypeAssertion" ||
|
||||
arg.type === "TSAsExpression" ||
|
||||
arg.type === "FunctionExpression" ||
|
||||
(arg.type === "ArrowFunctionExpression" &&
|
||||
|
@ -4348,7 +4356,8 @@ function printExportDeclaration(path, options, print) {
|
|||
decl.declaration.type !== "TSAbstractClassDeclaration" &&
|
||||
decl.declaration.type !== "TSInterfaceDeclaration" &&
|
||||
decl.declaration.type !== "DeclareClass" &&
|
||||
decl.declaration.type !== "DeclareFunction")
|
||||
decl.declaration.type !== "DeclareFunction" &&
|
||||
decl.declaration.type !== "TSDeclareFunction")
|
||||
) {
|
||||
parts.push(semi);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,23 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`abstract.ts 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
abstract class AbstractSocket {
|
||||
createSocket?(): Promise<string>
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
abstract class AbstractSocket {
|
||||
createSocket?(): Promise<string>;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`classExpression.ts 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
abstract class AbstractSocket {
|
||||
createSocket?(): Promise<string>
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ambientDeclarations.ts 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
declare type a = true;
|
||||
declare function b(): 'hello';
|
||||
declare const foo = 'bar';
|
||||
declare var qux: boolean;
|
||||
declare enum YO {}
|
||||
declare interface c {}
|
||||
declare class d {}
|
||||
declare module e {}
|
||||
declare module "g" {}
|
||||
declare namespace f {}
|
||||
|
||||
=====================================output=====================================
|
||||
declare type a = true;
|
||||
declare function b(): "hello";
|
||||
declare const foo = "bar";
|
||||
declare var qux: boolean;
|
||||
declare enum YO {}
|
||||
declare interface c {}
|
||||
declare class d {}
|
||||
declare module e {}
|
||||
declare module "g" {}
|
||||
declare namespace f {}
|
||||
|
||||
================================================================================
|
||||
`;
|
|
@ -0,0 +1,10 @@
|
|||
declare type a = true;
|
||||
declare function b(): 'hello';
|
||||
declare const foo = 'bar';
|
||||
declare var qux: boolean;
|
||||
declare enum YO {}
|
||||
declare interface c {}
|
||||
declare class d {}
|
||||
declare module e {}
|
||||
declare module "g" {}
|
||||
declare namespace f {}
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname, ["typescript"]);
|
|
@ -102,3 +102,16 @@ printWidth: 80
|
|||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`url.tsx 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const link = <a href="example.com">http://example.com</a>
|
||||
=====================================output=====================================
|
||||
const link = <a href="example.com">http://example.com</a>;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
const link = <a href="example.com">http://example.com</a>
|
14
yarn.lock
14
yarn.lock
|
@ -5763,16 +5763,18 @@ typedarray@^0.0.6:
|
|||
version "0.0.6"
|
||||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
||||
|
||||
typescript-estree@6.0.0-rc.1:
|
||||
version "6.0.0-rc.1"
|
||||
resolved "https://registry.yarnpkg.com/typescript-estree/-/typescript-estree-6.0.0-rc.1.tgz#2bc3d89d206ebdfa04cdebd9acf03aed9fff8860"
|
||||
typescript-estree@15.0.0:
|
||||
version "15.0.0"
|
||||
resolved "https://registry.yarnpkg.com/typescript-estree/-/typescript-estree-15.0.0.tgz#1fdc98b8e3bec0f5cdb00a90d8cfc4395d848a86"
|
||||
integrity sha512-5/dqC8RPfa2jiaY9SSozUM/l3DKT1TuJgJw6SFOfd/Lr3yRjeids8exv1t77W6zeMJ0QGKgU1ZV6eJg/8CjN+w==
|
||||
dependencies:
|
||||
lodash.unescape "4.0.1"
|
||||
semver "5.5.0"
|
||||
|
||||
typescript@3.2.1:
|
||||
version "3.2.1"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.1.tgz#0b7a04b8cf3868188de914d9568bd030f0c56192"
|
||||
typescript@3.2.2:
|
||||
version "3.2.2"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
|
||||
integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==
|
||||
|
||||
ua-parser-js@^0.7.9:
|
||||
version "0.7.17"
|
||||
|
|
Loading…
Reference in New Issue