Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 4 additions & 1 deletion Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ var harnessSources = harnessCoreSources.concat([
"projectErrors.ts",
"matchFiles.ts",
"initializeTSConfig.ts",
"extractMethods.ts",
"extractConstants.ts",
"extractFunctions.ts",
"extractRanges.ts",
"extractTestHelpers.ts",
"printer.ts",
"textChanges.ts",
"telemetry.ts",
Expand Down
12 changes: 11 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3703,13 +3703,23 @@
"code": 95002
},

"Extract function": {
"Extract symbol": {
"category": "Message",
"code": 95003
},

"Extract to {0}": {
"category": "Message",
"code": 95004
},

"Extract function": {
"category": "Message",
"code": 95005
},

"Extract constant": {
"category": "Message",
"code": 95006
}
}
5 changes: 4 additions & 1 deletion src/harness/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@
"./unittests/printer.ts",
"./unittests/transform.ts",
"./unittests/customTransforms.ts",
"./unittests/extractMethods.ts",
"./unittests/extractConstants.ts",
"./unittests/extractFunctions.ts",
"./unittests/extractRanges.ts",
"./unittests/extractTestHelpers.ts",
"./unittests/textChanges.ts",
"./unittests/telemetry.ts",
"./unittests/languageService.ts",
Expand Down
80 changes: 80 additions & 0 deletions src/harness/unittests/extractConstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/// <reference path="extractTestHelpers.ts" />

namespace ts {
describe("extractConstants", () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extractConstants [](start = 14, length = 16)

This test coverage isn't great because I didn't want to revise everything as soon as I updated the insertion locations.

testExtractConstant("extractConstant_TopLevel",
`let x = [#|1|];`);

testExtractConstant("extractConstant_Namespace",
`namespace N {
let x = [#|1|];
}`);

testExtractConstant("extractConstant_Class",
`class C {
x = [#|1|];
}`);

testExtractConstant("extractConstant_Method",
`class C {
M() {
let x = [#|1|];
}
}`);

testExtractConstant("extractConstant_Function",
`function F() {
let x = [#|1|];
}`);

testExtractConstant("extractConstant_ExpressionStatement",
`[#|"hello";|]`);

testExtractConstant("extractConstant_ExpressionStatementExpression",
`[#|"hello"|];`);

testExtractConstant("extractConstant_BlockScopes_NoDependencies",
`for (let i = 0; i < 10; i++) {
for (let j = 0; j < 10; j++) {
let x = [#|1|];
}
}`);

testExtractConstant("extractConstant_ClassInsertionPosition",
`class C {
a = 1;
b = 2;
M1() { }
M2() { }
M3() {
let x = [#|1|];
}
}`);

testExtractConstantFailed("extractConstant_Parameters",
`function F() {
let w = 1;
let x = [#|w + 1|];
}`);

testExtractConstantFailed("extractConstant_TypeParameters",
`function F<T>(t: T) {
let x = [#|t + 1|];
}`);

testExtractConstantFailed("extractConstant_BlockScopes_Dependencies",
`for (let i = 0; i < 10; i++) {
for (let j = 0; j < 10; j++) {
let x = [#|i + 1|];
}
}`);
});

function testExtractConstant(caption: string, text: string) {
testExtractSymbol(caption, text, "extractConstant", Diagnostics.Extract_constant);
}

function testExtractConstantFailed(caption: string, text: string) {
testExtractSymbolFailed(caption, text, Diagnostics.Extract_constant);
}
}
Loading