Fixes to emit / format for codeFix (#18486)

This commit is contained in:
Andy
2017-09-14 14:57:03 -07:00
committed by Mohamed Hegazy
parent b62d5f6696
commit 9639b52fcd
5 changed files with 56 additions and 5 deletions

View File

@@ -2417,6 +2417,12 @@ namespace ts {
const isEmpty = isUndefined || children.length === 0 || start >= children.length || count === 0;
if (isEmpty && format & ListFormat.OptionalIfEmpty) {
if (onBeforeEmitNodeArray) {
onBeforeEmitNodeArray(children);
}
if (onAfterEmitNodeArray) {
onAfterEmitNodeArray(children);
}
return;
}

View File

@@ -757,9 +757,8 @@ namespace ts.formatting {
return true;
case SyntaxKind.Block: {
const blockParent = context.currentTokenParent.parent;
if (blockParent.kind !== SyntaxKind.ArrowFunction &&
blockParent.kind !== SyntaxKind.FunctionExpression
) {
// In a codefix scenario, we can't rely on parents being set. So just always return true.
if (!blockParent || blockParent.kind !== SyntaxKind.ArrowFunction && blockParent.kind !== SyntaxKind.FunctionExpression) {
return true;
}
}

View File

@@ -2,14 +2,14 @@
// @allowNonTsExtensions: true
// @Filename: test123.js
//// [|var bar = 10, /*1*/foo = function() { };
//// var bar = 10, /*1*/foo = function() { };
//// /*2*/foo.prototype.instanceMethod1 = function() { return "this is name"; };
//// /*3*/foo.prototype.instanceMethod2 = () => { return "this is name"; };
//// /*4*/foo.prototype.instanceProp1 = "hello";
//// /*5*/foo.prototype.instanceProp2 = undefined;
//// /*6*/foo.staticProp = "world";
//// /*7*/foo.staticMethod1 = function() { return "this is static name"; };
//// /*8*/foo.staticMethod2 = () => "this is static name";|]
//// /*8*/foo.staticMethod2 = () => "this is static name";
['1', '2', '3', '4', '5', '6', '7', '8'].forEach(m => verify.applicableRefactorAvailableAtMarker(m));

View File

@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
// @allowNonTsExtensions: true
// @Filename: /a.js
////function /**/MyClass() {
////}
////MyClass.prototype.f = function(x) {
//// switch (x) {
//// case 0:
//// }
////}
verify.applicableRefactorAvailableAtMarker("");
verify.fileAfterApplyingRefactorAtMarker("",
`class MyClass {
constructor() {
}
f(x) {
switch (x) {
case 0:
}
}
}
`,
'Convert to ES2015 class', 'convert');

View File

@@ -0,0 +1,21 @@
/// <reference path='fourslash.ts' />
// @allowNonTsExtensions: true
// @Filename: /a.js
////function /**/MyClass() {
////}
////MyClass.prototype.foo = function() {
//// ({ bar: () => { } })
////}
verify.applicableRefactorAvailableAtMarker("");
verify.fileAfterApplyingRefactorAtMarker("",
`class MyClass {
constructor() {
}
foo() {
({ bar: () => { } });
}
}
`,
'Convert to ES2015 class', 'convert');