Skip to content

Commit

Permalink
feat: Support TS 3.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Dec 8, 2018
1 parent a9c190b commit e800f8b
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 95 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@
"source-map-support": "^0.5.5",
"ts-nameof": "^1.0.0",
"ts-node": "7.0.0",
"ts-simple-ast": "19.0.0",
"ts-simple-ast": "19.1.0",
"tslint": "^5.11.0",
"ttypescript": "1.5.5",
"typescript-3.0.1": "npm:typescript@3.0.1",
"typescript-3.0.3": "npm:typescript@3.0.3",
"typescript-3.1.6": "npm:typescript@3.1.6"
"typescript-3.1.6": "npm:typescript@3.1.6",
"typescript-3.2.2": "npm:typescript@3.2.2"
},
"standard-version": {
"tagPrefix": ""
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/ast/base/ModuledNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export function ModuledNode<T extends Constructor<ModuledNodeExtensionType>>(Bas
const symbol = identifier.getSymbol();
if (symbol == null)
return;
yield* getDeclarationsForSymbol(symbol.getAliasedSymbol());
yield* getDeclarationsForSymbol(symbol.getAliasedSymbol() || symbol);
}
else if (TypeGuards.isImportClause(declaration)) {
const identifier = declaration.getDefaultImport();
Expand All @@ -374,7 +374,7 @@ export function ModuledNode<T extends Constructor<ModuledNodeExtensionType>>(Bas
const symbol = identifier.getSymbol();
if (symbol == null)
return;
yield* getDeclarationsForSymbol(symbol.getAliasedSymbol());
yield* getDeclarationsForSymbol(symbol.getAliasedSymbol() || symbol);
}
else
yield declaration;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/ast/type/TypeParameterDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class TypeParameterDeclaration extends TypeParameterDeclarationBase<ts.Ty
* @param text - Text to set as the constraint.
*/
setConstraint(text: string | WriterFunction) {
text = this._getTextWithQueuedChildIndentation(text);
text = this.getParent()._getTextWithQueuedChildIndentation(text);
if (StringUtils.isNullOrWhitespace(text)) {
this.removeConstraint();
return this;
Expand Down Expand Up @@ -80,7 +80,7 @@ export class TypeParameterDeclaration extends TypeParameterDeclarationBase<ts.Ty
* @param text - Text to set as the default type node.
*/
setDefault(text: string | WriterFunction) {
text = this._getTextWithQueuedChildIndentation(text);
text = this.getParent()._getTextWithQueuedChildIndentation(text);
if (StringUtils.isNullOrWhitespace(text)) {
this.removeDefault();
return this;
Expand Down
10 changes: 5 additions & 5 deletions src/tests/compiler/tools/languageServiceTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ describe(nameof(LanguageService), () => {

describe(nameof<LanguageService>(l => l.getEditsForRefactor), () => {
it("should get edits for known refactor 'Move to a new file'", () => {
const { sourceFile, project } = getInfoFromText("export class A {}; function f(){return new A(); }", { filePath: "/file.ts" });
const classId = sourceFile.getClassOrThrow("A").getNameNodeOrThrow();
const results = project.getLanguageService().getEditsForRefactor(sourceFile, {}, classId, "Move to a new file", "Move to a new file", {});
const { sourceFile, project } = getInfoFromText("export class A {}\nfunction f() { return new A(); }", { filePath: "/file.ts" });
const nameNode = sourceFile.getClassOrThrow("A").getNameNodeOrThrow();
const results = project.getLanguageService().getEditsForRefactor(sourceFile, {}, nameNode, "Move to a new file", "Move to a new file", {});
expect(results!.getEdits()).to.lengthOf(2);
expect(results!.getRenameFilePath()).to.be.undefined;
expect(results!.getRenameLocation()).to.be.undefined;
Expand All @@ -135,14 +135,14 @@ describe(nameof(LanguageService), () => {
span: { start: 0, length: 0 }
}, {
newText: "",
span: { start: 0, length: 17 }
span: { start: 0, length: 18 }
}]
});

checkFileTextChanges(edit2!, {
fileName: "/A.ts",
textChanges: [{
newText: "export class A {\n}",
newText: "export class A {\n}" + (ts.version === "3.2.2" ? "\n" : ""),
span: { start: 0, length: 0 }
}]
});
Expand Down
1 change: 1 addition & 0 deletions src/tests/projectTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ describe(nameof(Project), () => {
fileSystem.writeFileSync("/node_modules/@types/jquery/package.json",
`{ "name": "@types/jquery", "version": "1.0.0", "typeScriptVersion": "2.3" }`);

project.createSourceFile("test.ts", "import * as ts from 'jquery';");
return project;
}

Expand Down

0 comments on commit e800f8b

Please sign in to comment.