Skip to content

[#356] Add support for TypeScript 2.1.4 #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 27, 2016
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
2 changes: 1 addition & 1 deletion .baseDir.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

Please don't check the .vscode files into this project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are helpful for contributors, otherwise contributors have to manually figure out how to set up the debugger (this can be especially difficult for TS-based projects to know what the correct parameters are). It would be preferable to leave them in, there's nothing specific to my workspace that's in the files.

Copy link
Member

Choose a reason for hiding this comment

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

The thing specific to your workspace is VS code. Should we check in configurations for other IDEs too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like to optimize my projects for a specific xplat IDE, which is VS Code for me--it provides a happy path for contributors. However, you are the maintainer so would you be OK adding the configuration to the CONTRIBUTING readme? That provides a copy/paste way for contributors who want to use VS Code at least.

// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"cwd": "${workspaceRoot}",
"args": [
"--no-timeouts"
],
"outFiles": [
"${workspaceRoot}/lib/**/*.js",
"${workspaceRoot}/test/**/*.js"
],
"sourceMaps": true
}
]
}
11 changes: 11 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-w", "-p", "."],
"showOutput": "silent",
"isWatching": true,
"problemMatcher": "$tsc-watch"
}
2 changes: 1 addition & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function(grunt)
pkg: grunt.file.readJSON('package.json'),
ts: {
typedoc: {
tsconfig: true
tsconfig: { passThrough: true }
},
typescript: {
options: {
Expand Down
2 changes: 1 addition & 1 deletion index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"progress": "^1.1.8",
"shelljs": "^0.7.0",
"typedoc-default-themes": "^0.4.0",
"typescript": "2.0.6"
"typescript": "2.1.4"
},
"devDependencies": {
"grunt": "^1.0.1",
Expand All @@ -55,7 +55,7 @@
"grunt-contrib-watch": "^1.0.0",
"grunt-mocha-istanbul": "^5.0.1",
"grunt-string-replace": "^1.2.0",
"grunt-ts": "^5.3.0-beta.2",
"grunt-ts": "^5.5.1",
"istanbul": "^0.4.1",
"mocha": "^3.0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/factories/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function getRawComment(node:ts.Node):string {
}

var sourceFile = _ts.getSourceFileOfNode(node);
var comments = _ts.getJsDocComments(node, sourceFile);
var comments = _ts.getJSDocCommentRanges(node, sourceFile.text);
if (comments && comments.length) {
var comment:ts.CommentRange;
if (node.kind == ts.SyntaxKind.SourceFile) {
Expand Down
17 changes: 11 additions & 6 deletions src/lib/converter/factories/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export function createDeclaration(context:Context, node:ts.Node, kind:Reflection
}
}

var modifiers = ts.getCombinedModifierFlags(node);

// Test whether the node is exported
var isExported:boolean;
if (container.kindOf([ReflectionKind.Module, ReflectionKind.ExternalModule])) {
Expand All @@ -54,17 +56,18 @@ export function createDeclaration(context:Context, node:ts.Node, kind:Reflection
if (kind == ReflectionKind.ExternalModule) {
isExported = true; // Always mark external modules as exported
} else if (node.parent && node.parent.kind == ts.SyntaxKind.VariableDeclarationList) {
isExported = isExported || !!(node.parent.parent.flags & ts.NodeFlags.Export)
var parentModifiers = ts.getCombinedModifierFlags(node.parent.parent);
isExported = isExported || !!(parentModifiers & ts.ModifierFlags.Export)
} else {
isExported = isExported || !!(node.flags & ts.NodeFlags.Export);
isExported = isExported || !!(modifiers & ts.ModifierFlags.Export);
}

if (!isExported && context.converter.excludeNotExported) {
return null;
}

// Test whether the node is private, when inheriting ignore private members
var isPrivate = !!(node.flags & ts.NodeFlags.Private);
var isPrivate = !!(modifiers & ts.ModifierFlags.Private);
if (context.isInherit && isPrivate) {
return null;
}
Expand All @@ -73,7 +76,7 @@ export function createDeclaration(context:Context, node:ts.Node, kind:Reflection
var isConstructorProperty:boolean = false;
var isStatic = false;
if (nonStaticKinds.indexOf(kind) == -1) {
isStatic = !!(node.flags & ts.NodeFlags.Static);
isStatic = !!(modifiers & ts.ModifierFlags.Static);
if (container.kind == ReflectionKind.Class) {
if (node.parent && node.parent.kind == ts.SyntaxKind.Constructor) {
isConstructorProperty = true;
Expand Down Expand Up @@ -126,9 +129,11 @@ export function createDeclaration(context:Context, node:ts.Node, kind:Reflection
* @returns The reflection populated with the values of the given node.
*/
function setupDeclaration(context:Context, reflection:DeclarationReflection, node:ts.Node) {
var modifiers = ts.getCombinedModifierFlags(node);

reflection.setFlag(ReflectionFlag.External, context.isExternal);
reflection.setFlag(ReflectionFlag.Protected, !!(node.flags & ts.NodeFlags.Protected));
reflection.setFlag(ReflectionFlag.Public, !!(node.flags & ts.NodeFlags.Public));
reflection.setFlag(ReflectionFlag.Protected, !!(modifiers & ts.ModifierFlags.Protected));
reflection.setFlag(ReflectionFlag.Public, !!(modifiers & ts.ModifierFlags.Public));
reflection.setFlag(ReflectionFlag.Optional, !!(node['questionToken']));

if (
Expand Down
3 changes: 2 additions & 1 deletion src/lib/converter/nodes/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class ClassConverter extends ConverterNodeComponent<ts.ClassDeclaration>
context.withScope(reflection, node.typeParameters, () => {
if (node.members) {
node.members.forEach((member) => {
const privateMember = (member.flags & ts.NodeFlags.Private) > 0;
const modifiers = ts.getCombinedModifierFlags(member);
const privateMember = (modifiers & ts.ModifierFlags.Private) > 0;
const exclude = context.converter.excludePrivate ? privateMember : false;

if (!exclude) {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/converter/nodes/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ export class ConstructorConverter extends ConverterNodeComponent<ts.ConstructorD
* @return The resulting reflection or NULL.
*/
private addParameterProperty(context:Context, parameter:ts.ParameterDeclaration, comment:Comment) {
var visibility = parameter.flags & (ts.NodeFlags.Public | ts.NodeFlags.Protected | ts.NodeFlags.Private);
var modifiers = ts.getCombinedModifierFlags(parameter);
var visibility = modifiers & (ts.ModifierFlags.Public | ts.ModifierFlags.Protected | ts.ModifierFlags.Private);
if (!visibility) return;

const privateParameter = parameter.flags & ts.NodeFlags.Private;
const privateParameter = modifiers & ts.ModifierFlags.Private;
if (privateParameter && context.converter.excludePrivate) return;

var property = createDeclaration(context, parameter, ReflectionKind.Property);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/converter/nodes/variable-statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class VariableStatementConverter extends ConverterNodeComponent<ts.Variab
* @param node The binding pattern node that should be analyzed.
*/
convertBindingPattern(context:Context, node:ts.BindingPattern) {
node.elements.forEach((element:ts.BindingElement) => {
this.owner.convertNode(context, <any>element);
(node.elements as ts.BindingElement[]).forEach((element:ts.BindingElement) => {
this.owner.convertNode(context, element);

if (_ts.isBindingPattern(element.name)) {
this.convertBindingPattern(context, <ts.BindingPattern>element.name);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/types/binding-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class BindingArrayConverter extends ConverterTypeComponent implements ITy
convertNode(context:Context, node:ts.BindingPattern):Type {
var types:Type[] = [];

node.elements.forEach((element) => {
(node.elements as ts.BindingElement[]).forEach((element) => {
types.push(this.owner.convertType(context, element));
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/types/binding-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class BindingObjectConverter extends ConverterTypeComponent implements IT
context.registerReflection(declaration, null);
context.trigger(Converter.EVENT_CREATE_DECLARATION, declaration, node);
context.withScope(declaration, () => {
node.elements.forEach((element) => {
(node.elements as ts.BindingElement[]).forEach((element) => {
this.owner.convertNode(context, element);
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/lib/converter/types/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export class ReferenceConverter extends ConverterTypeComponent implements ITypeN
* Test whether this converter can handle the given TypeScript node.
*/
supportsNode(context:Context, node:ts.TypeReferenceNode, type:ts.TypeReference):boolean {
return !!(type.flags & ts.TypeFlags.ObjectType);
return !!(type.flags & ts.TypeFlags.Object);
}


/**
* Test whether this converter can handle the given TypeScript type.
*/
supportsType(context:Context, type:ts.TypeReference):boolean {
return !!(type.flags & ts.TypeFlags.ObjectType);
return !!(type.flags & ts.TypeFlags.Object);
}


Expand All @@ -53,7 +53,7 @@ export class ReferenceConverter extends ConverterTypeComponent implements ITypeN
convertNode(context:Context, node:ts.TypeReferenceNode, type:ts.TypeReference):Type {
if (!type.symbol) {
return new IntrinsicType('Object');
} else if (type.symbol.flags & ts.SymbolFlags.TypeLiteral || type.symbol.flags & ts.SymbolFlags.ObjectLiteral) {
} else if (type.symbol.declarations && (type.symbol.flags & ts.SymbolFlags.TypeLiteral || type.symbol.flags & ts.SymbolFlags.ObjectLiteral)) {
return this.convertLiteral(context, type.symbol, node);
}

Expand Down Expand Up @@ -83,7 +83,7 @@ export class ReferenceConverter extends ConverterTypeComponent implements ITypeN
convertType(context:Context, type:ts.TypeReference):Type {
if (!type.symbol) {
return new IntrinsicType('Object');
} else if (type.symbol.flags & ts.SymbolFlags.TypeLiteral || type.symbol.flags & ts.SymbolFlags.ObjectLiteral) {
} else if (type.symbol.declarations && (type.symbol.flags & ts.SymbolFlags.TypeLiteral || type.symbol.flags & ts.SymbolFlags.ObjectLiteral)) {
return this.convertLiteral(context, type.symbol);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/types/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class TupleConverter extends ConverterTypeComponent implements ITypeConve
* Test whether this converter can handle the given TypeScript type.
*/
supportsType(context:Context, type:ts.TypeReference):boolean {
return !!(type.flags & ts.TypeFlags.Tuple);
return !!(type.objectFlags & ts.ObjectFlags.Tuple);
}


Expand Down
61 changes: 27 additions & 34 deletions src/lib/ts-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,105 +6,104 @@ const tsany = ts as any;
*/
declare module "typescript" {
interface Symbol {
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L2166
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/types.ts#L2658
id?: number;
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L2168
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/types.ts#L2660
parent?: ts.Symbol;
}

interface Node {
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L469
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/types.ts#L497
symbol?: ts.Symbol;
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L472
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/types.ts#L500
localSymbol?: ts.Symbol;
// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L471
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/types.ts#L499
nextContainer?: ts.Node;
}
}


/**
* These functions are in "core" and are marked as @internal:
* https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L4-L5
* https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/core.ts#L9-L10
*/

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L655-L656
export function createCompilerDiagnostic(message: ts.DiagnosticMessage, ...args: any[]): ts.Diagnostic;
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/core.ts#L1133-LL1134
export function createCompilerDiagnostic(message: ts.DiagnosticMessage, ...args: (string | number)[]): ts.Diagnostic;
export function createCompilerDiagnostic(message: ts.DiagnosticMessage): ts.Diagnostic;
export function createCompilerDiagnostic() {
return tsany.createCompilerDiagnostic.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L701
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/core.ts#L1191
export function compareValues<T>(a: T, b: T): number {
return tsany.compareValues.apply(this, arguments); // Actually returns a ts.Comparison which is also internal
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L790
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/core.ts#L1281
export function normalizeSlashes(path: string): string {
return tsany.normalizeSlashes.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L795
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/core.ts#L1288
export function getRootLength(path: string): number {
return tsany.getRootLength.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/core.ts#L852-L854
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/core.ts#L1368-L1370
export function getDirectoryPath(path: ts.Path): ts.Path;
export function getDirectoryPath(path: string): string;
export function getDirectoryPath(path: string): any;
export function getDirectoryPath() {
return tsany.getDirectoryPath.apply(this, arguments);
}

/**
* These functions are in "utilities" and are marked as @internal:
* https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L3-L4
* https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L3-L4
*/

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L188
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L152
export function getSourceFileOfNode(node: ts.Node): ts.SourceFile {
return tsany.getSourceFileOfNode.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L333
export function getTextOfNode(node: ts.Node, includeTrivia?: boolean): string {
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L301
export function getTextOfNode(node: ts.Node, includeTrivia = false): string {
return tsany.getTextOfNode.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L438
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L473
export function declarationNameToString(name: ts.DeclarationName): string {
return tsany.declarationNameToString.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L598
export function getJsDocComments(node: ts.Node, sourceFileOfNode: ts.SourceFile) {
return tsany.getJsDocComments.apply(this, arguments);
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L1423
export function getJSDocCommentRanges(node: ts.Node, text: string) {
return tsany.getJSDocCommentRanges.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L1487
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L3738
export function isBindingPattern(node: ts.Node): node is ts.BindingPattern {
return tsany.isBindingPattern.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L1696
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L1729
export function getClassExtendsHeritageClauseElement(node: ts.ClassLikeDeclaration | ts.InterfaceDeclaration) {
return tsany.getClassExtendsHeritageClauseElement.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L1701
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L1734
export function getClassImplementsHeritageClauseElements(node: ts.ClassLikeDeclaration) {
return tsany.getClassImplementsHeritageClauseElements.apply(this, arguments);
}

// https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/utilities.ts#L1706
// https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L1739
export function getInterfaceBaseTypeNodes(node: ts.InterfaceDeclaration) {
return tsany.getInterfaceBaseTypeNodes.apply(this, arguments);
}

/**
* https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L2789-L2924
* https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/types.ts#L3347
* This is large enum of char codes.
*
* Faking the enum as a var (only certain codes are used by TypeDoc)
Expand All @@ -117,18 +116,12 @@ export const CharacterCodes: {
at: number;
} = tsany.CharacterCodes;

/**
* https://github.com/Microsoft/TypeScript/blob/v2.0.5/src/compiler/types.ts#L2334
* Duplicating the interface definition :(
*/
// interface IntrinsicType extends ts.Type {
// intrinsicName: string;
// }

export const optionDeclarations: CommandLineOption[] = tsany.optionDeclarations;

/**
* Command line options
*
* https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/types.ts#L3344
*/
export interface CommandLineOption {
name: string;
Expand Down
Loading