Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,12 @@ namespace ts {

const isEmpty = isUndefined || start >= children.length || count === 0;
if (isEmpty && format & ListFormat.OptionalIfEmpty) {
if (onBeforeEmitNodeArray) {
onBeforeEmitNodeArray(children);
}
if (onAfterEmitNodeArray) {
onAfterEmitNodeArray(children);
}
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3500,7 +3500,7 @@ ${code}
expected = makeWhitespaceVisible(expected);
actual = makeWhitespaceVisible(actual);
}
return `Expected:\n${expected}\nActual:${actual}`;
return `Expected:\n${expected}\nActual:\n${actual}`;
}

function differOnlyByWhitespace(a: string, b: string) {
Expand Down
5 changes: 2 additions & 3 deletions src/services/formatting/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/fourslash/convertFunctionToEs6Class3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
25 changes: 25 additions & 0 deletions tests/cases/fourslash/convertFunctionToEs6Class_emptySwitchCase.ts
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
@@ -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');